Solved

Searching for lots of files

Posted on 2003-11-18
4
245 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
ID: 9771423
Do they have anything in common, like a common word or modified date?
0
 
LVL 83

Accepted Solution

by:
oBdA earned 350 total points
ID: 9774626
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
ID: 9777265
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 83

Expert Comment

by:oBdA
ID: 9777457
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In the hope of saving someone else's sanity... About a year ago we bought a Cisco 1921 router with two ADSL/VDSL EHWIC cards to load balance local network traffic over the two broadband lines we have, but we couldn't get the routing to work consi…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 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

18 Experts available now in Live!

Get 1:1 Help Now