Unziping file and generating log based on

Microsoft Windows server 2003 enterprise
November 2, 2009 at 01:10:03
Specs: Windows XP
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


See More: Unziping file and generating log based on

Report •


#1
November 2, 2009 at 01:39:04
@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


Report •

#2
November 2, 2009 at 04:04:05
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


Report •

#3
November 3, 2009 at 01:46:35
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


Report •

Related Solutions

#4
November 3, 2009 at 02:56:33
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


Report •

#5
November 3, 2009 at 03:19:17
Unless you post the output, I have no idea.


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

M2


Report •

#6
November 4, 2009 at 02:16:24
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


Report •

#7
November 6, 2009 at 23:10:43
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)


Report •


Ask Question