Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

zip files in multiple directories

Status
Not open for further replies.

tcdrake

Technical User
May 20, 2003
16
0
0
US
I need some help with a script.

Here is the directory structure.

c:\ftp\2
3
4
5
etc....

In each of the folders 2,3,4,5,etc are files I need to zip up and name
to todays date. Below is what I have to zip but it only works if I but the AWK created exe and batch file in each directory. I would like one master file to run it all. Below is what I have so far....
Code:
BEGIN{ 
i=1 
timetab(z,time() - 86400) 
while (i < 2) { 
yesterday = time()-(i*86400) 
timetab(y,yesterday) 
printf("if exist em.dbf ren em.dbf em%s%02s%02s.dbf 
\n",substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "get.bat" 
printf("if exist gnd.dbf ren gnd.dbf td%s%02s%02s.dbf 
\n",substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "get.bat" 
printf("if exist gn.dbf ren gn.dbf ln%s%02s%02s.dbf 
\n",substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "get.bat" 
i++ 

} 

printf("c:\\progra~1\\winzip\\wzzip -m  %s%02s%02s.zip *.dbf 
\n",z["YEAR"],z["MONTH"],z["DAY"])  > "get.bat"

Any ideas?
 
Maybe pass in the directory name to awk (use the -v option) and then include this path name in the commands.

Just a thought ... bed time here really :)
 
When you generate your list file, do it from the c:\ftp directory and use dir /s /b, then you can pull the directory names from the output.

Annihilannic.
 
Here is what I came up with but it doesn't really work. The following script goes into each directory and renames the files with the date. Then it zips them with the date as the name. The issue is that it works fine if I only have one file in each directory which needs to be renamed. It craps out if I need more than one file renamed. Here is the code.

Code:
BEGIN{
printf("REM READ STORE FILE AND ZIP EACH DIRECTORY\n") > "doit.bat"
i=1
timetab(z,time() - 86400) 
while (i < 2){
yesterday = time()-(i*86400)
timetab(y,yesterday)

while ( (getline < "Stores.txt") > 0) 

printf("if exist c:\\test\\%s\\e.dbf ren %s\\e%s%02s%02s.dbf\n",$2,$2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "doit.bat"
printf("if exist c:\\test\\%s\\gnd.dbf ren %s\\gd%s%02s%02s.dbf\n",$2,$2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "doit.bat"
printf("if exist c:\\test\\%s\\gn.dbf ren %s\\gn%s%02s%02s.dbf\n",$2,$2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "doit.bat"
printf("if exist c:\\test\\%s\\g.dbf ren %s\\g%s%02s%02s.dbf\n",$2,$2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "doit.bat"


i++
}

while ( (getline < "Store.txt") > 0)

printf("c:\\progra~1\\winzip\\wzzip.exe -m C:\\test\%s\\%s%02s%02s.zip C:\\test\\%s\\*.*\n",$1 ,z["YEAR"],z["MONTH"],z["DAY"], $1) > "doit.bat" 

}

I know it is probably alot more cumbersome then what you would come up with but hey, I am a newbie. Thanks for your help.
 
Nevermind...rookie mistake. I forgot to add two brackets.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top