Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: rename base...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 10 Topic 2205 of 2241
Post > Topic >>

Re: rename based on file name

by Cesar Rabak <csrabak@[EMAIL PROTECTED] > Mar 26, 2008 at 11:26 AM

tcdrake escreveu:
> I have a couple of scripts which for the most part work but I need to
> change it up a bit based on new requirments. Here is what is currently
> happening.
> 
> Get 80 zip files in named yyyymmdd-(location).zip
> Unzip each zip to a folder based on location code in zip name.
> Rename the files to include yesterdays date.
> Zip up files and move to anyother directory based on location code.
> 
> All the above works fine if I only get one zip file per location per
> day. This is an issue when I get more than one zip file per location.
> So if I get 20080323-1.zip and 20080324-1.zip because the code I am
> using will just unzip the first one then unzip the second to the same
> folder which will over write the first ones before I am able to rename
> them.

This is due the way you devised your solution as a series of batch 
processess.

If you inline the calling of the commands instead of lumping them in 
batch files to call then latter this would not be a problem.

Caveat emptor: very superficial analysis!

> 
> What I need to do is unzip and rename the files based on the date of
> the zip file then zip all of the files into one zip based on
> yyyymmdd.zip.
> 
> Here is my current code which came with a lot of help from this group
> and a forum :)
> 
> CODE BELOW
> 
> 
> @[EMAIL PROTECTED]
 off
> cd\
> cd po\test\users\test
> dir /b *.zip | awk -f  C:\test\unzip.awk  C:\stores.txt - > C:
> \unzip.cmd
> The above calls the awk code below
> CODE
> BEGIN{
>         UnZipCommand1 = "c:\\progra~1\\winzip\\wzunzip.exe -e -s C:\\po
> \\test\\users\\test\\"
>         UnZipCommand2 = " @[EMAIL PROTECTED]
 C:\\po\\test\\users\\test\\"
> # Making the field separator -, ., or TAB makes it work for both
> # the file name and the tab delimited map file.
>         FS = "[-.\t]"
>         print "@[EMAIL PROTECTED]
 off"
> 
> 
> }
> 
> 
> {
>         if( NR == FNR ) {
> # The file containing the location map.
>                 Table[ $1 ] = $2
>         }
>         else {
> # The directory listing on STDIN
> 
> # The source is the filename in the DIR listing.
>                 Fname = $0
> # The target is the given parent directory followed by the location
> # from the map file corresponding to the location number in the
> # file name (the second field).
>                 Target = Table[ $2 ]
> # It may be desirable to ad a trailing "\\" to the command.
>                 Command = UnZipCommand1 Fname UnZipCommand2 Target
>                 print Command
>         }
> 
> 
> 
> }
> 
> Then I run the following to rename the files based on the date, zip
> and move to the correct directory.
> 
> CODE BELOW
> 
> 
> BEGIN{
> 
> i=0
> timetab(z,time() - 86400)
> while (i < 2){
> yesterday = time()-(i*86400)
> timetab(y,yesterday)
> {
> while ( (getline < "Stores.txt") > 0)
> {
> printf("REN c:\\po\test\users\test\\%s\\emp.dbf em%s%02s%02s.dbf\n",
> $2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\\doit.bat"
> printf("REN c:\\po\test\users\test\\%s\\gndtndr.dbf td%s%02s%02s.dbf
> \n",$2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\
> \doit.bat"
> printf("REN c:\\po\test\users\test\\%s\\gndline.dbf ln%s%02s%02s.dbf
> \n",$2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\
> \doit.bat"
> printf("REN c:\\po\test\users\test\\%s\\gnditem.dbf it%s%02s%02s.dbf
> \n",$2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\
> \doit.bat"
> printf("REN c:\\po\test\users\test\\%s\\itm.dbf i%s%02s%02s.dbf\n",
> $2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\\doit.bat"
> printf("REN c:\\po\test\users\test\\%s\\trans.log t%s%02s%02s.log\n",
> $2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\\doit.bat"
> printf("REN c:\\po\test\users\test\\%s\\cit.dbf ci%s%02s%02s.dbf\n",
> $2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\\doit.bat"
> printf("REN c:\\po\test\users\test\\%s\\cat.dbf ca%s%02s%02s.dbf\n",
> $2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\\doit.bat"
> printf("REN c:\\po\test\users\test\\%s\\gndrevn.dbf gr%s%02s%02s.dbf
> \n",$2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\
> \doit.bat"
> printf("REN c:\\po\test\users\test\\%s\\rev.dbf rv%s%02s%02s.dbf\n",
> $2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\\doit.bat"
> printf("REN c:\\po\test\users\test\\%s\\gndturn.dbf gt%s%02s%02s.dbf
> \n",$2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\
> \doit.bat"
> printf("REN c:\\po\test\users\test\\%s\\tdr.dbf t%s%02s%02s.dbf\n",
> $2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\\doit.bat"
> printf("REN c:\\po\test\users\test\\%s\\pro.dbf p%s%02s%02s.dbf\n",
> $2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\\doit.bat"
> printf("REN c:\\po\test\users\test\\%s\\cmp.dbf c%s%02s%02s.dbf\n",
> $2,substr(y["YEAR"],3,2),y["MONTH"],y["DAY"])  > "C:\\test\\doit.bat"
> i++
> 
> }
> 
> while ( (getline < "Store.txt") > 0)
> 
> printf("c:\\progra~1\\winzip\\wzzip.exe -m -s C:\\po\test\users\test\\
> %s\\%s%02s%02s.zip C:\\po\test\users\test\\%s\\*.*\n",
> $1 ,z["YEAR"],z["MONTH"],z["DAY"], $1) > "C:\\test\\doit.bat"
> 
> 
> }
> 
> while ((getline <"Store1.txt") > 0)
> printf("XCOPY /s C:\\po\test\users\test\\%s\\*.zip C:\\iFtpSvc\\info\
> \users\\download\\test\\%s\\\n",$1,$1) > "C:\\test\\doit.bat"
> 
> }
> 
> 
> while ((getline <"Store2.txt") > 0)
> printf("del C:\\po\test\users\test\\%s\\*.zip\n",$1) > "C:\\test\
> \doit.bat"
> printf("del C:\\po\test\users\test\\*.zip -w 10\n")  > "C:\\test\
> \doit.bat"
> 
> 
> }

This is half off-topic: This whole script could be substituted by a 
doit.bat with three parameters to substitute directly in the batch file.

> 
> I think one option is to have a piece of code which goes through the
> directory and makes a list of all the files. Then use that list to
> rename the unzipped files based on the list. I just not sure how to
> implement it. Any ideas?




 10 Posts in Topic:
rename based on file name
tcdrake <rymills@[EMAI  2008-03-26 05:16:13 
Re: rename based on file name
Cesar Rabak <csrabak@[  2008-03-26 11:26:44 
Re: rename based on file name
Ed Morton <morton@[EMA  2008-03-26 10:04:06 
Re: rename based on file name
Ted Davis <tdavis@[EMA  2008-03-26 11:35:42 
Re: rename based on file name
Cesar Rabak <csrabak@[  2008-03-26 18:18:11 
Re: rename based on file name
Ted Davis <tdavis@[EMA  2008-03-26 19:10:01 
Re: rename based on file name
tcdrake <rymills@[EMAI  2008-03-28 08:30:29 
Re: rename based on file name
tcdrake <rymills@[EMAI  2008-03-28 10:08:26 
Re: rename based on file name
Ted Davis <tdavis@[EMA  2008-03-28 15:17:02 
Re: rename based on file name
Cesar Rabak <csrabak@[  2008-03-28 20:40:45 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 5:09:16 CDT 2008.