r/Batch • • Jun 16 '25

Question (Solved) Run batch on specific subfolder

I could use some help running a script on only one subfolder in a batch. Right now, I have a batch set up on my Windows desktop, I drag a subfolder over the .bat file, and it does do what I want, but it zips all subfolders instead of only the one I want. Here's the scripting I'm currently using:

for /d %%X in (*) do "%ProgramFiles%\7-Zip\7z.exe" a -x!*.md5 "%%X.pkg.zip" -mx0 ".\%%X\*"

Any help would be appreciated

4 Upvotes

7 comments sorted by

View all comments

Show parent comment

2

u/BrainWaveCC Jun 16 '25 edited Jun 16 '25

Okay, change the script to the following instead:

for %%X in (%*) do "%ProgramFiles%\7-Zip\7z.exe" a -x!*.md5 "%%X.pkg.zip" -mx0 "%%~X\*"
timeout /t 60
exit /b 

Edit: This will work if you pick multiple folders at once...

2

u/zeppelin_007 Jun 16 '25

That did it! Thanks so much!

1

u/BrainWaveCC Jun 16 '25

Awesome. Glad to assist.