On Fri, 07 Mar 2008 07:32:06 -0800, tcdrake wrote:
> On Mar 7, 9:25 am, tcdrake <rymi...@[EMAIL PROTECTED]
> wrote:
>> I get 80 zips each day. So today the zips will be named 20080306-1.zip,
>> 20080306-2.zip, 20080306-3.zip, etc.. The number after the dash is the
>> location number. I need to unzip each location to a folder based on
>> different location numbers. So location 1 based on the zip name goes to
>> location 090909. Location 2 based on the zip name goes to location
>> 034850987. I have an excel file which assigns locations to each other.
>> Does that help? I hope so as I could really use the help on this.- Hide
>> quoted text -
>>
I can't test this with TAWK - I'm not sure I even still have it on any of
my machines, definitely not on this one.
Assuming that the location map is exported from Excel as a tab delimited
file with each entry on a separate line in the form
number_in_filename\tdestination_directory
then this batch file generates another batch file to do the actual work.
@[EMAIL PROTECTED]
off
dir /b *.zip | awk -fscript_file.awk map_file.txt - > }{.cmd
when satisfied that }{.cmd does what you want, add these two lines
call }{
del }{.cmd
The script is commented and in fully expanded syntax for clarity.
BEGIN{
UnZipCommand1 = "c:\\progra~1\\winzip\\wzunzip.exe -e -s "
UnZipCommand2 = " c:\\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
}
}
If it doesn't work with TAWK, install gawk - it's better for almost
everything except that it doesn't have true multidimensional arrays and
isn't a compiler <http://gnuwin32.sourceforge.net/packages/gawk.htm>.
Using this map
1 101
2 102
3 103
4 104
5 105
and files named 20080307-1.zip,20080307-2.zip, 0080307-3.zip,
20080307-4.zip, and 20080307-5.zip
it generated this output file (lines may have wrapped)
@[EMAIL PROTECTED]
off
c:\progra~1\winzip\wzunzip.exe -e -s 20080307-1.zip c:\test\101
c:\progra~1\winzip\wzunzip.exe -e -s 20080307-2.zip c:\test\102
c:\progra~1\winzip\wzunzip.exe -e -s 20080307-3.zip c:\test\103
c:\progra~1\winzip\wzunzip.exe -e -s 20080307-4.zip c:\test\104
c:\progra~1\winzip\wzunzip.exe -e -s 20080307-5.zip c:\test\105
--
T.E.D. (tdavis@[EMAIL PROTECTED]
) MST (Missouri University of Science and
Technology)
used to be UMR (University of Missouri - Rolla).


|