1.

Solve : BATCH PROGRAM TO RETRIEVE FILES ON WINDOWS 7?

Answer»

i would like to CREATE a batch program that searches for .csv file in numerous folders on a directory. if the file is found in any folder it creates a new folder and PLACES all the files in it.

example my path is U:/WED/processin_folders within this location there are over 300 folders.
if i type lets say broward. the batch program should go through each folder to search for broward, when it is found it places the files in a new folder call RESULTS. there can be more than one broward files, or a broward in each folder.Just clarifying the task:

Quote from: dstyles on November 08, 2012, 08:05:39 PM

i would like to create a batch program that searches for .csv file in numerous folders on a directory. if the file is found in any folder it creates a new folder and places all the files in it.

Creates a new folder where?

Do you want the files moved or copied into it?

Quote from:
example my path is U:/WED/processin_folders within this location there are over 300 folders.
if i type lets say broward. the batch program should go through each folder to search for broward, when it is found it places the files in a new folder call RESULTS. there can be more than one broward files, or a broward in each folder.

What do you want to do with the duplicates? i want the files to be copied to the home directory U:/WED create a folder called RESULTS, EACH FILE IN the each folder is dated so there should not be any duplicatesQuote from: dstyles on November 08, 2012, 09:05:16 PM
i want the files to be copied to the home directory U:/WED create a folder called RESULTS,

Ok..

Quote from:
EACH FILE IN the each folder is dated so there should not be any duplicates

If they have the same filename then they can't all be put in the same folder, without overwriting the one that was there already.

If there were say 28 broward.csv files, how do you want to HANDLE them?we could rename each file example broward_1_(date) broward_2_(date) etc each in sequential orderThis is untested: click on it and type in your search term. It doesn't add the date to the filename as the filenames can already be sorted by date in your file viewer.

It adds a number after the filename. 0 is the first one, then 1, 2, 3 etc.

Code: [Select]@echo off
set var=
set /p "var=Type your search string for .csv files: "
if not defined var goto :EOF
set "source=U:\WED\processin_folders"
dir "%source%\*.csv" /b /s /a-d |find /i "%var%">filelist.tmp
for /f "delims=" %%a in (filelist.tmp) do call :NEXT "%%a"
del filelist.tmp
goto :EOF

:next
set c=0
md "%source%\Results" 2>nul
:loop
if exist "%source%\Results\%~n1_%c%%~x1" set /a c=c+1 & goto :loop
echo copying %1 to "%source%\Results\%~n1_%c%%~x1"
copy /b "%~1" "%source%\Results\%~n1_%c%%~x1"
goto :EOFTHANKS I WILL TEST IT


Discussion

No Comment Found