windows - Issue with batch script with vbscript command in the batch file -
i new batch scripting , vbscript. want convert .xlsx excel files .csv excel files, in multiple directories (recursively). example:
main directory subdirectory1 file1.xlsx file2.xlsx subdirectory2 file3.xlsx file4.xlsx i have made batch script:
for /r %%a in (*.xlsx) ( set filename=%%a exceltocsv.vbs %filename% *.csv ) inside loop exceltocsv.vbs. got code thread convert xls csv on command line, , have tried top 2 answers (both don't require downloading anything).
if wscript.arguments.count < 2 wscript.echo "error! please specify source path , destination. usage: xlstocsv sourcepath.xls destination.csv" wscript.quit end if dim oexcel set oexcel = createobject("excel.application") dim obook set obook = oexcel.workbooks.open(wscript.arguments.item(0)) obook.saveas wscript.arguments.item(1), 6 obook.close false oexcel.quit wscript.echo "done" the error saying exceltocsv.vbs file cannot accessed. however, believe batch script working, example say:
set filename=c:\folder\subfolder\test1.xlsx then calls:
exceltocsv.vbs c:\folder\subfolder\test1.xlsx *.csv i not sure problem , confused.
the vbs needs in same directory bat file.
the issue variable expansion rules in for loop mean filename wont set current file variables value; use %%a instead:
for /r %%a in (*.xlsx) ( exceltocsv.vbs "%%a" "%%~dpna.csv" ) you passing string "*.csv" script wont work, %%~dpna.csv takes file name in %%a , changes extension .csv.
the quotes there allow spaces in paths.
Comments
Post a Comment