Page 1 of 1

copying and moving zip files using the bat script

Posted: 22 Jul 2010 07:11
by ashrafb
Hi,

I want to search the zip files (.wav files are zipped) by putting the name of the file in a text file and put the resultant files in one designated folder; for example I have list of zip files with the following names
20080101.zip
20080201.zip
20080301.zip

now i put let say 200801 in a text file which provides the input parameter to my script code which in turn automatically go to all the folder and sub folders of c drive and automatically extracts all the files that have "200801" set as their names and copy them in c:\result folder

any help with such scrit will be greatly appriciated

Re: copying and moving zip files using the bat script

Posted: 22 Jul 2010 10:22
by aGerman
1st) If you want to search the entire C: drive it will take a very long time to find the file.

2nd) If you want to extract the found file you need a packaging application with command switches for extracting the files. Which would you use and how is the syntax?

3rd) You want to first extract the files and after that copy the extracted files into a predefined folder? Which files are the extracted files and which files did exist before?

Think about it and come back with more informations.

Regards
aGerman

Re: copying and moving zip files using the bat script

Posted: 22 Jul 2010 12:16
by ashrafb
Hi aGerman,

many thanks for the reply. below mentioned is the script that i'm currently using to pull the files and put them in the destination directory. the limitation of this script is that it does not serach the sub folders in the source directory. I mean the files (recording in wav format) that i'm trying to serach could be in the root of the main directory or in any of the sub directory. But the below script goes only to the root of the main directory, therefore, as a work around i have to copy all the files one by one from each sub folder and put them in the root of parent folder so the script can easily pick up the recordings from there.
All i want is to make to script also seraching the files in the sub folders
--------------
rem A short script meant to accellerate a repetitive task. Author: JV



rem first version: 03/21/2003

rem Major modification 04/25/2003



rem Source text file: one phone number per line



rem To customize: modify only the paths below. Note that when modifying

rem source_dir and dest_dir, also update source_drive and dest_drive.



set source_drive=d:

set source_dir=d:\

set dest_drive=C:

set dest_dir=C:\WavCopy\wavoutput\

set text_file=C:\WavCopy\search_list.txt

set report_file=C:\WavCopy\wavreport.txt



del %report_file%

mkdir %dest_dir%

%source_drive%

cd %source_dir%



rem pause



rem run search through all zip files

rem %%~nz expands to just zipfile filename, without extension



for %%z in (*.ZIP) do for /F %%f in (%text_file%) do unzip -C %%z %%~nz\*%%f*.wav -d %dest_dir%



rem pause

rem run search through uncompressed, dated folders



for /D %%d in (*.) do for /F %%f in (%text_file%) do copy %%d\*%%f*.wav %dest_dir%



rem pause

rem run search through root directory, uncompressed wav files



for /F %%f in (%text_file%) do copy *%%f*.wav %dest_dir%



rem Move any wav files in subdirectories, to the root of the destination folder

rem to enable searching for duplicates below.



%dest_drive%

cd %dest_dir%

rem pause



rem for /D %%d in (*.) do move %dest_dir%\%%d\*.wav %dest_dir%



rem Generate report of any phone numbers with more than one file

rem the oldest of the duplicates should then be manually deleted.

rem The directory listing is sorted with oldest first.



rem This will eventually be supplanted with a vbscript that does

rem the process automatically.



for /F %%f in (%text_file%) do dir /o:d %dest_dir%*%%f*.wav >> c:\temp\wavreport.txt

Re: copying and moving zip files using the bat script

Posted: 22 Jul 2010 12:28
by aGerman
To search in the subfolders you could process the output of the DIR command.
For the current directory and subfolders:

Code: Select all

for /f "delims=" %%z in ('dir /a-d /b /s *.ZIP') do ...



For drive C: and subfolders:

Code: Select all

for /f "delims=" %%z in ('dir /a-d /b /s C:\*.ZIP') do ...


Have a look at the /s switch...

Regards
aGerman

Re: copying and moving zip files using the bat script

Posted: 26 Jul 2010 11:12
by ashrafb
Hi aGerman,

many thanks for the reply. I did try it but it didnt work as i'm very novice in scripting. Can you please do me a favor ?. Please write me a whole script that i can use to run in my environment. You can use the one i posted earlier, or develop a new simple and short code that does the job.

I'm really sorry to ask u that but i have tried all possible combination to append your line of script into my code, but somehow it doesnt work.

I'd really appriciate if you could please send me a ready to run code for this.

the simple background of the requirment is, all want to search multiple zip files using a text file (abc.txt) as an in put parameter. the reason for text file is that i can enter multiple file names which acts as a input parameter to the script for file searching in multiple folders/subfolders in a particular drive and then placing the resultant files in seprate designated folder.

thanks in advance for ur help on this

Re: copying and moving zip files using the bat script

Posted: 26 Jul 2010 15:06
by aGerman
Not that sure if this will work for you:

Code: Select all

@echo off &setlocal

set source_dir=d:\
set dest_dir=C:\WavCopy\wavoutput\

set text_file=C:\WavCopy\search_list.txt
set report_file=C:\WavCopy\wavreport.txt

del %report_file%
mkdir %dest_dir% 2>nul

cd /d %source_dir%

for /f "delims=" %%z in ('dir /a-d /b /s *.ZIP') do for /F %%f in (%text_file%) do unzip -C %%z %%~nz\*%%f*.wav -d %dest_dir%

:: No idea what this is good for, but it's a part of your origin code:
for /D %%d in (*.) do for /F %%f in (%text_file%) do copy %%d\*%%f*.wav %dest_dir%

cd /d %dest_dir%

for /F %%f in (%text_file%) do dir /o:d %dest_dir%*%%f*.wav >> c:\temp\wavreport.txt



Regards
aGerman