Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Searching for lots of files

Posted on 2003-11-18
4
Medium Priority
?
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 85

Accepted Solution

by:
oBdA earned 1400 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 85

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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 month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

604 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