Computing.Net > Forums > Programming > Unziping file and generating log based on

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.

Unziping file and generating log based on

Reply to Message Icon

Name: Vandu_1983
Date: November 2, 2009 at 01:10:03 Pacific
OS: Windows XP
Product: Microsoft Windows server 2003 enterprise
Subcategory: Batch
Comment:

HI All,

I want to write a batch script which will Unzip all the .Zip files from a folder A(inside the Folder A, there will be more than 1 .Zip files) and each unzipped file will have a sub directory structure and these sub directories will have some files inside them, I have to copy all these files from the subdirectories and place them in C:\To_BE_Processed folder, but if a file already exists in the folder C:\To_BE_Processed then the existing file should be moved to C:\Already_exsists folder and a log file(.txt) has to generated with the file name is already existing in the directory.

I am using the below script for extracting and placing the files from one zip file to my target directory. I need to implement the same for multiple zip files and if a file already exists in the destination it has to moved to another directory and a log file has to be generated ..How to write a batch script for the same.

@echo off & setLocal EnableDELAYedExpansion

pushd C:\Data
unzip CDR_02112009.ZIP

for /f "tokens=* delims= " %%a in ('dir/s/b/a-d C:\Data') do (
copy "%%a" C:\To_BE_Processed
)

Thanks & Regards,
Vandu



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: November 2, 2009 at 01:39:04 Pacific
Reply:

@echo off & setLocal EnableDELAYedExpansion

pushd C:\Data
unzip CDR_02112009.ZIP

for /f "tokens=* delims= " %%a in ('dir/s/b/a-d C:\Data') do (
if exist "C:\To_BE_Processed\%%a" (
move "C:\To_BE_Processed\%%a" C:\Already_exsists
>> log echo %%a was moved
)
copy "%%a" C:\To_BE_Processed
)


=====================================
Helping others achieve escape felicity

M2


0

Response Number 2
Name: Vandu_1983
Date: November 2, 2009 at 04:04:05 Pacific
Reply:

Hi,

I tried the batch script,but I am not the script is not tracking the exsiting files.

When I executed the script it is replacing the already exsiting one in the To_BE_Processed dir.

To_BE_Processed will have a history of files..so I don't want to replace any of the exsiting files,if a file is exsiting then it has to be moved to Already_exsists folder and the new file should be inserted in the To_BE_Processed and a log has to be created in the Log folder about that a particular file name already exsists.

Thanks & regards,
Vandu


0

Response Number 3
Name: Mechanix2Go
Date: November 3, 2009 at 01:46:35 Pacific
Reply:

Try this and post a few lines of output.

==============================
@echo off & setLocal EnableDELAYedExpansion

pushd C:\Data
unzip CDR_02112009.ZIP

for /f "tokens=* delims= " %%a in ('dir/b/a-d C:\Data') do (
if exist "C:\To_BE_Processed\%%a" (
echo move "C:\To_BE_Processed\%%a" C:\Already_exsists
>> log echo %%a was moved
)
echo copy "%%a" C:\To_BE_Processed
)


=====================================
Helping others achieve escape felicity

M2


0

Response Number 4
Name: Vandu_1983
Date: November 3, 2009 at 02:56:33 Pacific
Reply:

HI,

I have executed the script it is unzipping the file and then it is giving the error has FILE NOT FOUND.

It is not copying the extracted files to any of the destination folders and log is not generated.

Thanks,
Vandu


0

Response Number 5
Name: Mechanix2Go
Date: November 3, 2009 at 03:19:17 Pacific
Reply:

Unless you post the output, I have no idea.


=====================================
Helping others achieve escape felicity

M2


0

Related Posts

See More



Response Number 6
Name: Vandu_1983
Date: November 4, 2009 at 02:16:24 Pacific
Reply:

Hi ,

I tried to debugg the error and I found that this part if exist "C:\To_BE_Processed\%%a" ( is causing the problem the %%a is holding the filename with the path of the file and the script is not able to paste the files in either of the target folders,,can you please let me know how can we seperate the path and file names so that we can take only the file names and send them to the deastination folders as required.

Thanks,
Vadu


0

Response Number 7
Name: nbrane
Date: November 6, 2009 at 23:10:43 Pacific
Reply:

if path is consistent: (f/e: path will be "strip\path\name")
set s=%%a
:replace 'strip\path\name' with null
set s=!s:strip\path\name=!

or if path same length every time (f/e 22):
:cut bytes 1-22 off var.
set s=%%a
set s=!s:~22!
(then use '!s!' instead of '%%a' in all subsequent op.s)


0

Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Unziping file and generating log based on

logging RS232 (com1?) and save file www.computing.net/answers/programming/logging-rs232-com1-and-save-file/13835.html

Move a XML file based on content www.computing.net/answers/programming/move-a-xml-file-based-on-content/18945.html

Deleting files based on Date www.computing.net/answers/programming/deleting-files-based-on-date/15215.html