Unzip and Appended the .Zip name

Microsoft Windows server 2003 enterprise
November 2, 2009 at 01:44:51
Specs: Win Server 2003, intel
Hi ,

I need to write a batch script which will unzip the .Zip files from a folder and each .Zip file will have some .csv files inside,I need to unzip all the Zip files and appened the last 3 charcters of the .Zip file to the file name as below.

Zip file name - XYZ_2_21.Zip and inside these zip I have 3 .csv files.

My output should be

How can I write the batch script to acheive this.


See More: Unzip and Appended the .Zip name

Report •

November 5, 2009 at 18:43:19
how are the files named inside the zipfile? (ie what, if any, extension). you would need to put the unzipped files into their own directory unless they have unique extensions.
begin with:
@echo off & setlocal EnableDelayedExpansion
:make/change to temp directory
md temp
copy test.zip temp
cd temp
pkunzip test.zip
:if they always have a 3-byte extension, it's pretty simple:
for %%a in (*.*) do (
:same from here down both versions
set c=%%a
set c=!c:~0,-4!
set c=!c!.csv
ren %%a !c!)

if the extensions are unique such that the files won't be mixed up with existing files, you wouldn't need to do any of the directory operations, just change the *.* to the unique extension. for ex. if extension is "txt" AND there are no files with .txt extension in the current working dir.:
@echo off & setlocal EnableDelayedExpansion
pkunzip test.zip
for %%a in (*.txt) do (

and the rest would be the same from that point.
if the files inside the zipfile have various lengths of extensions and not always 3 chars, you would need more code to locate the dot then chop it off. without more specfic info, can't tell you much better than this.

Report •
Related Solutions

Ask Question