Computer Hope

Microsoft => Microsoft DOS => Topic started by: NyteOwl on June 27, 2008, 08:26:10 AM

Title: Batch file to unzip multiple files...
Post by: NyteOwl on June 27, 2008, 08:26:10 AM
I have a large number of zip files containing historical data that I need to uncompress. 

The directory hierarchy is yearly parent folders with monthly sub-folders that each contain multiple zip files.

What I need is a batch file that I can run from any yearly folder that will open each monthly folder, unzip the files, then move to the next monthly file until the entire year's worth of data has been uncompressed.  I've been given a custom executable to handle all uncompressing routine, so I just need something to open the January directory so I can call the executable, and then when finished, change to the February directory to repeat the process, and so on until all 12 monthly directories for that particular year have been processed.

Sounds simple enough, but I thought maybe while a beginner like me was trying to figure it out someone with a lot more knowledge might have a quick solution for me.

Thanks in advance...jack
Title: Re: Batch file to unzip multiple files...
Post by: NyteOwl on June 27, 2008, 09:20:49 AM
Well, I figured out how to do this the hard way, but suggestions are still welcome...
Title: Re: Batch file to unzip multiple files...
Post by: blastman on June 27, 2008, 09:49:45 AM
I'm sure a loop would look nicier, but if I've understood you right, this should do....


Code: [Select]
@echo off

set /p year="Enter year:  "

cd c:\path\to\folder\conatining\years\%year%

cd jan

start /wait application_name.exe

cd feb

start /wait application_name.exe

cd..

cd mar

start /wait application_name.exe

cd..

cd apr

start /wait application_name.exe

cd..

cd may

start /wait application_name.exe
cd..

cd jun

start /wait application_name.exe

cd..

cd jul

start /wait application_name.exe

cd..

cd aug

start /wait application_name.exe

cd..

cd Sept

start /wait application_name.exe

cd..

cd oct

start /wait application_name.exe

cd..

cd nov

start /wait application_name.exe

cd..

cd dec

start /wait application_name.exe


Title: Re: Batch file to unzip multiple files...
Post by: NyteOwl on June 27, 2008, 10:27:07 AM
Thanks blastman, but that's real similar to what I ended up doing.

I was hoping for a loop, but I suspect the processing will be complete by EOB today...
Title: Re: Batch file to unzip multiple files...
Post by: BC_Programmer on June 27, 2008, 08:15:06 PM
instead of:
Code: [Select]

cd jan

start /wait application_name.exe

cd feb

start /wait application_name.exe

cd..

cd mar

start /wait application_name.exe

cd..

cd apr

start /wait application_name.exe

cd..

cd may

start /wait application_name.exe
cd..

cd jun

start /wait application_name.exe

cd..

cd jul

start /wait application_name.exe

cd..

cd aug

start /wait application_name.exe

cd..

cd Sept

start /wait application_name.exe

cd..

cd oct

start /wait application_name.exe

cd..

cd nov

start /wait application_name.exe

cd..

cd dec

start /wait application_name.exe



why not:

Code: [Select]
for %%P in (jan feb mar apr may jun July Sept Oct Nov Dec) do cd %P&start /wait application_name.exe@cd ..


if the only folders are the month folders, it would be even simpler...

Code: [Select]
for %%P /D (*) do do cd %P&start /wait application_name.exe@cd ..

Title: Re: Batch file to unzip multiple files...
Post by: blastman on June 28, 2008, 01:36:35 AM
Code: [Select]
for %%P /D (*) do do cd %P&start /wait application_name.exe@cd ..

Show off!!!! ;) ;D

I knew that it could be achived like that, but I wa unsure how. Could you break it down for me, what part of the syantx is doing what, so I konw for next time??

cheers
Title: Re: Batch file to unzip multiple files...
Post by: BC_Programmer on June 28, 2008, 09:15:02 AM
oops- there is a mistake there- it should be:
Code: [Select]
for %%P /D (*) do cd %P&start /wait application_name.exe&cd ..

I had do twice, and the @ sign instead of the & before cd ..


the For /D command will iterate through all folders that match the given criteria. In this case, all of them (*) for each folder, I execute three commands (separated by &'s), first, change to the dir, then execute the program, then change back to the parent folder (cd ..)