Solved

Searching for lots of files

Posted on 2003-11-18
4
244 Views
Last Modified: 2010-04-14
I have a list of about 300 files.  How do I search for thesefiles.  The search function only allows me to paste in a few characters, probably 255.  Does anyone know any free programs or can I do it with a batch file.  

I just want to be able to find these files and move them to a single directory.

Thanks.
0
Comment
Question by:mollari_uk
  • 2
4 Comments
 
LVL 3

Expert Comment

by:Popeyediceclay
Comment Utility
Do they have anything in common, like a common word or modified date?
0
 
LVL 82

Accepted Solution

by:
oBdA earned 350 total points
Comment Utility
Something like that?
Currently, I'm assuming that there are no duplicate filenames in the list (since you want to put them in a single directory), and that there are no duplicate files on the disk.
This takes the path and name of the list with the names (I'm assuming one name per line) and searches, downwards from the given root directory, for the file name. If found, it will be copied to the given target directory. If it's not found, the file name is recorded in a log file (directory and name of the script file name, with the extension ".log"), so that you can use a copy(!) of that list to hunt for the missing files on another drive (or whatever else you're planning to do with it).
Adapt the settings to your need; currently, the script is in test mode, so it will search for the files, but it will not actually move them, it will only display the "move" command. Remove the "ECHO" where indicated to "arm" the script.
Start it, for example, like this:
FindList D:\Temp\files.txt

====8<----[FindList.cmd]----
@echo off
setlocal
:: *** The directory to start the search in:
set SearchDir=D:\Temp
:: *** The directory to move the files into:
set TargetDir=D:\Test
:: *** Logfile (*D*rive, *P*ath and *N*ame of the script, with the extension ".log"):
set LogFile=%~dpn0.log

if %1.==. goto leave
set SearchFile=%~1
if not exist "%SearchFile%" goto leave
if exist "%LogFile%" del "%LogFile%"
pushd "%SearchDir%"
for /f "delims=" %%a in ('type "%SearchFile%"') do call :process %%a
goto leave

:process
set FileName=%*
set SourceDir=
echo Searching for %FileName% ...
for /f %%a in ('dir /b /s /a:-d "%FileName%" 2^>NUL') do set SourceDir=%%~dpa
if "%SourceDir%"=="" goto NotFound
echo ... found in %SourceDir%.
echo Moving %FileName% to %TargetDir% ...
:: *** Test mode; remove the "ECHO" in front of the next line to "arm" the script:
ECHO move %SourceDir%%FileName% %TargetDir%\%FileName%
echo ... done.
goto :eof

:NotFound
echo ... not found.
>>"%LogFile%" echo %FileName%
goto :eof

:leave
popd
====8<----[FindList.cmd]----
0
 

Author Comment

by:mollari_uk
Comment Utility
oBdA,

Thank for the script however I've got it to run with no errors however it doesn't do anything.  Here's my edited script.  I've increased the points on this question because I didn't expect such a good response.

I'm running this through a cmd prompt at the files directory, is that right too?

@echo off
setlocal
:: *** The directory to start the search in:
set SearchDir=T:\products\images\supplier products
:: *** The directory to move the files into:
set TargetDir=T:\upload data\amazon\images
:: *** Logfile (*D*rive, *P*ath and *N*ame of the script, with the extension ".log"):
set LogFile=%~T:\upload data\amazon\findlist.log

**AM I DOING THE BIT ABOVE WITH THE LOG RIGHT?**

if %1.==. goto leave
set SearchFile=%~1
if not exist "%SearchFile%" goto leave
if exist "%LogFile%" del "%LogFile%"
pushd "%SearchDir%"
for /f "delims=" %%a in ('type "%SearchFile%"') do call :process %%a
goto leave

:process
set FileName=%*
set SourceDir=
echo Searching for %FileName% ...
for /f %%a in ('dir /b /s /a:-d "%FileName%" 2^>NUL') do set SourceDir=%%~dpa
if "%SourceDir%"=="" goto NotFound
echo ... found in %SourceDir%.
echo Moving %FileName% to %TargetDir% ...
:: *** Test mode; remove the "ECHO" in front of the next line to "arm" the script:
move %SourceDir%%FileName% %TargetDir%\%FileName%
echo ... done.
goto :eof

:NotFound
echo ... not found.
>>"%LogFile%" echo %FileName%
goto :eof

:leave
popd


Thanks for the help so far.
0
 
LVL 82

Expert Comment

by:oBdA
Comment Utility
You can start the script from any directory (from a command prompt, yes); it will then search the directory and all subdirectories specified in %SearchDir%.
It needs the full(!) path and name of the list with the file names (one file name per line) to be searched for as first argument.
You can leave the default logfile; the "%~dpn0" construction will automatically expand to the script's directory and name.
This is a bit improved and more userfriendly; I've already set the directories to your needs and set it back to test mode.

====8<----[FindList.cmd]----
@echo off
setlocal
:: *** The directory to start the search in:
set SearchDir=T:\products\images\supplier products
:: *** The directory to move the files into:
set TargetDir=T:\upload data\amazon\images

:: *** Logfile (*D*rive, *P*ath and *N*ame of the script, with the extension ".log"):
set LogFile=%~dpn0.log

if %1.==. goto err_Argument
set SearchFile=%~1
if not exist "%SearchFile%" goto err_SearchFile
if exist "%LogFile%" del "%LogFile%"
pushd "%SearchDir%"
for /f "delims=" %%a in ('type "%SearchFile%"') do call :process %%~a
popd
goto leave

:process
set FileName=%*
set SourceDir=
echo Searching for %FileName% ...
for /f %%a in ('dir /b /s /a:-d "%FileName%" 2^>NUL') do set SourceDir=%%~dpa
if "%SourceDir%"=="" goto NotFound
echo ... found in %SourceDir%.
echo Moving %FileName% to %TargetDir% ...
:: *** Test mode; remove the "ECHO" in front of the next line to "arm" the script:
ECHO move %SourceDir%%FileName% %TargetDir%\%FileName%
echo ... done.
goto :eof

:NotFound
echo ... not found.
>>"%LogFile%" echo %FileName%
goto :eof

:err_Argument
echo.
echo Please enter the full path and name of the file with the file names
echo to be searched as the first argument.
echo Example: %~n0 C:\Temp\namelist.txt
goto leave

:err_SearchFile
echo.
echo Error: The search file "%SearchFile%" could not be found.
goto leave

:leave
====8<----[FindList.cmd]----
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now