Seven
Seven

Reputation: 69

Search Sub Folders in Batch

I have written a script to search for .avi or .mkv files within a certain directory. Once found I launch a program that processes them and renames them. I am looking to find out how to modify the below script to also search sub folders.

For example. If I have test.avi or test.avi within Downloads the below works fine but if I have test.avi or test.mkv within Downloads/Test it does not work.

cd C:\Users\Administrator\Downloads
for %%X in (*.avi) do start "C:\Program Files (x86)\Rename\Rename.exe" %%X
for %%Y in (*.mkv) do start "C:\Program Files (x86)\Rename\Rename.exe" %%Y

Thanks.

Upvotes: 1

Views: 207

Answers (1)

foxidrive
foxidrive

Reputation: 41287

/r is a recursive switch. "" is needed in the start command when other quoted strings exist. /w pauses until the completion of each command. The "%%X" quotes allows for spaces etc in the names and paths.

cd C:\Users\Administrator\Downloads
for /r %%X in (*.avi) do start "" /w "C:\Program Files (x86)\Rename\Rename.exe" "%%X"
for /r %%Y in (*.mkv) do start "" /w "C:\Program Files (x86)\Rename\Rename.exe" "%%Y"

Upvotes: 1

Related Questions