Solved Apply .BAT routine to sub folders

May 19, 2013 at 15:51:50
Specs: Windows 8
I have this .bat file:

@echo off & setLocal enableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b *.cdg *.mp3') do (
pkzipc -add %%~Na %%a
)

This routine runs fine when I place it in the folder with the files that need to be changed. However I would like this routine to cover multiple folders i.e. place it in parent folder and have it apply to all sub folders.


See More: Apply .BAT routine to sub folders

Report •

✔ Best Answer
May 20, 2013 at 20:05:01
The only things i can see are: spaces-in-filenames (be cursed unto eternity!), and fully-qualified path to the zip file (otherwise, the various zips will be built in the outlying directories, and not the base).
pushd D:\files
:: add the following?
set base=%cd%
for /f "tokens=* delims= " %%i in ('dir/b/s/ad') do (
pushd "%%i"
for /f "tokens=* delims= " %%a in ('dir/b *.cdg *.mp3 2^>nul') do (
pkzipc -add "%base%\%%~Na" "%%a"
)

maybe spaces-in-filenames (or folder names) is messing up the pkz commandline, the quotes around the targets might fix that. The other is just a minor glitch (or not, depending if you want the zips to be scattered or concentrated).



#1
May 19, 2013 at 19:44:07
@echo off & setLocal enableDELAYedeXpansion

pushd D:\files

for /f "tokens=* delims= " %%i in ('dir/b/s/ad') do (
pushd "%%i"
for /f "tokens=* delims= " %%a in ('dir/b *.cdg *.mp3 2^>nul') do (
echo pkzipc -add %%~Na %%a
)
popd
)

=====================
M2 Golden-Triangle


Report •

#2
May 19, 2013 at 20:26:27
It seems to list all the files which is good but it does not zip the files. I have added pkzipc to my PATH but it still only list the files. Am I missing some programs that I might need to support the code you wrote?

Report •

#3
May 19, 2013 at 20:30:36
"the files. Am I missing some programs that I might need to support the code you wrote?"

Take out the echo in front of pkzipc to activate.

=====================
M2 Golden-Triangle


Report •

Related Solutions

#4
May 19, 2013 at 21:42:22
Now it let's me pause the CMD window. It says " 'pkzipc' is not recognized as an internal or external command ..."

Report •

#5
May 19, 2013 at 21:59:15
You either have pkzipc in the path or you don't.

You said the orig bat was working.

=====================
M2 Golden-Triangle


Report •

#6
May 20, 2013 at 15:14:50
Alright pkzipc is now in windows\system32 folder and now in the PATH but this error now displays "PKZIP: <E4> Unknown or illegal option"

Report •

#7
May 20, 2013 at 15:58:28
Page 188 of this manual
http://www.pkware.com/documents/man...
says the command you are trying doesn't work the way you think it does. Or there is a mistype, sure it's the right "spelling"?

:: mike


Report •

#8
May 20, 2013 at 20:05:01
✔ Best Answer
The only things i can see are: spaces-in-filenames (be cursed unto eternity!), and fully-qualified path to the zip file (otherwise, the various zips will be built in the outlying directories, and not the base).
pushd D:\files
:: add the following?
set base=%cd%
for /f "tokens=* delims= " %%i in ('dir/b/s/ad') do (
pushd "%%i"
for /f "tokens=* delims= " %%a in ('dir/b *.cdg *.mp3 2^>nul') do (
pkzipc -add "%base%\%%~Na" "%%a"
)

maybe spaces-in-filenames (or folder names) is messing up the pkz commandline, the quotes around the targets might fix that. The other is just a minor glitch (or not, depending if you want the zips to be scattered or concentrated).


Report •

#9
May 21, 2013 at 12:12:10
And that my friend totally did the trick! I forgot about the spaces and as soon I replaced the spaces with underscores, in the file names, bingo it worked like a charm.

Thanks for everyone's help. Now to start this for over 25,000 files, woot woot!


Report •

Ask Question