0

I have a folder with many subfolders (1000+) and inside the subfolders are a few excel files, in .xlsx format. I want to run a batch script from the main folder, which goes into each sub folder and changes each .xlsx Excel file into a .csv Excel file.

The formatting of the file system:

MainFolder
---subfolder1
----->file1.xlsx
---subfolder2
----->file2.xlsx

etc.

From this thread: Convert XLS to CSV on command line, I figured out that I can't just rename each .xlsx to .csv, so I made the ExceltoCSV.vbs file (the modified ScottF answer, second one down). My understanding is that I can make a for loop in a batch file to run ExceltoCSV.vbs for each sub folder. The following line of code is something i attempted, but it didn't work. It usually says *.xlsx file is not found.

for /R %%F in ("C:\MainFolder") do cscript ExceltoCSV.vbs *.xlsx *.csv

Also tried this:

for /d /r "C:\MainFolder" %%F in (.) do cscript ExceltoCSV.vbs "%%F\*.xlsx" *.csv

Error message:

C:\MainFolder\ExceltoCSV.vbs(17,1) Microsoft Excel: 'C:\MainFolder\folder1\*.xlsx' could not be found. Check the spelling of the file name, and verify that the file location is correct.
Community
  • 1
  • 1
needhelpwithR
  • 283
  • 1
  • 4
  • 15

1 Answers1

0

The VBS script you got from SO only takes a string as an input. What you'll need to do is create a loop with a regex pattern that builds those file names dynamically and then run the script with an input string representing each file name. Pseudo code:

for loop (iterate over file names in dir){
set $file_name=$iterated_file_name_from_loop

ExceltoCSV.vbs "$file_name.xlsx" *.csv

}
MiiinimalLogic
  • 820
  • 6
  • 11