Computing.Net > Forums > Programming > Unzip and Appended the .Zip name

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Unzip and Appended the .Zip name

Reply to Message Icon

Name: sunitha_1984
Date: November 2, 2009 at 01:44:51 Pacific
OS: Win Server 2003
CPU/Ram: intel
Product: Microsoft Windows server 2003 enterprise
Subcategory: Batch
Comment:

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
firstfile_2_21.csv
secondFile_2_21.csv
thirdfile_2_21.csv

How can I write the batch script to acheive this.

--Sunitha



Sponsored Link
Ads by Google

Response Number 1
Name: nbrane
Date: November 5, 2009 at 18:43:19 Pacific
Reply:

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.


0
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Unzip and Appended the .Zip name

Batch Scipt to Add the File Name to File www.computing.net/answers/programming/batch-scipt-to-add-the-file-name-to-file/19412.html

Unzip All the Zip files from a folder www.computing.net/answers/programming/unzip-all-the-zip-files-from-a-folder/20244.html

Appending the timestamp as a column www.computing.net/answers/programming/appending-the-timestamp-as-a-column/16587.html