Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do include sub-folders in my file conversion script?

I have modified a vbscript and batch file that allows me to convert HTML files to xlsx files in the current directory as follows

Script:

if WScript.Arguments.Count < 2 Then
    WScript.Echo "Please specify the source and the destination files"
    Wscript.Quit
End If

xlsx_format = 51

Set objFSO = CreateObject("Scripting.FileSystemObject")

src_file = objFSO.GetAbsolutePathName(Wscript.Arguments.Item(0))
dest_file = objFSO.GetAbsolutePathName(WScript.Arguments.Item(1))

Dim oExcel
Set oExcel = CreateObject("Excel.Application")

Dim oBook
Set oBook = oExcel.Workbooks.Open(src_file)

oBook.SaveAs dest_file, xlsx_format

oBook.Close False
oExcel.Quit

Batch file:

FOR /f "delims=" %%i IN ('DIR *.HTM* /b') DO to-xlsx.vbs "%%i" "%%~ni.xlsx"
del *.HTM /q

By including /s in the batch file I am able to convert files in the subfolders but they are still saved to the parent directory and I cant quite work out how to change that?

src_file is C:\Converter\Subfolder\FileName and dest_file is C:\Converter\FileName for a file in the subfolder

like image 353
J.Goddard Avatar asked Jul 15 '20 15:07

J.Goddard


People also ask

Can a folder have sub folders?

A folder stored within another folder. Technically, the nested folder is a "subfolder," and subfolders can also contain subfolders and so on up to a maximum level.

What is the difference between folders and sub folders?

Answer: is that subfolder is (computing) a folder within another folder while folder is (computing) a virtual container in a computer's file system, in which files and other folders may be stored the files and subfolders in a folder are usually related.


1 Answers

You will need to change

FOR /f "delims=" %%i IN ('DIR *.HTM* /b') DO to-xlsx.vbs "%%i" "%%~ni.xlsx"

to

FOR /R %%i IN (*.HTM* ) DO to-xlsx.vbs "%%i" "%%~ni.xlsx"

for /r means Recursive, so you are asking CMD to loop every file and his subdirectories, but only that they contain an .htm* file.

like image 185
Anic17 Avatar answered Sep 21 '22 17:09

Anic17