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
Solved

Searching for lots of files

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

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…
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

860 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