Solved

Searching for lots of files

Posted on 2003-11-18
4
248 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 84

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 84

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

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 article was originally published on Monitis Blog, you can check it  here . If you have responsibility for software in production, I bet you’d like to know more about it. I don’t mean that you’d like an extra peek into the bowels of the sour…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 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