Computing.Net > Forums > Programming > File search / locate Batch file.

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

File search / locate Batch file.

Reply to Message Icon

Name: 25zerotwo
Date: October 28, 2008 at 15:22:35 Pacific
OS: Vista Pro 32bit
CPU/Ram: 64 X2 3800+ 2.30Ghz
Comment:

Hello guys and girls.

Very keen to find out what code I should use within a batch file which will enable me to search for file names kept within a list(hopefully in a .txt file say list.txt) and then have the batch file locate from that list and print the file locations to a new file say results.txt

Any ideas?

To give some background which may help, I intend to keep track of certain new malware related files and would like to be able to quickly check a PC to see if any of the files listed are located within the 'test' machines folders/subfolders.

Many thanks for any help.

Chris



Sponsored Link
Ads by Google

Response Number 1
Name: Holla
Date: October 29, 2008 at 04:58:57 Pacific
Reply:

Hi 25zerotwo,

Long back, I had written a batch file called duplicate.bat to find duplicate files.
I think what you are asking is same as what this batch file does.
It expects the filenames in filelist.txt (may contain wildcards)
and searches for each entry in filelist.txt
The sample filelist.txt can contain entries like -
e.bat
mren.bat
*holla*
cmd.exe
*backup*


An example of a run with the above filelist.txt being present in current directory:
17:21++++++++++++++++ c:\holla\bat>duplicate "\Program Files" .
Given list of files to find duplicates:
==> e.bat
==> mren.bat
==> *holla*
==> cmd.exe
==> *backup*
Searching for duplicate files ....
c:\Program Files\Common Files\Roxio Shared\9.0\Tutorial\Graphics\backup_icon.gif
c:\Program Files\Common Files\Roxio Shared\9.0\Tutorial\Graphics\backup_icon_hilite.gif
c:\Program Files\Common Files\Roxio Shared\9.0\Tutorial\Graphics\rc_backup.gif
c:\Program Files\Common Files\Roxio Shared\9.0\Tutorial\Graphics\rc_backup_project_icon.gif
c:\Program Files\Motorola Phone Tools\BackupRestore.mht
c:\Program Files\Motorola Phone Tools\MotoBackup.jpg
c:\Program Files\Motorola Phone Tools\Custom\BackupRestoreWizWm.bmp
c:\holla\bat\mren.bat
c:\holla\bat\backup.bat
c:\holla\bat\Excluded4backup.txt
c:\holla\bat\Included4backup.txt


Now, the batch file: Run it with /? to see the usage.

@echo off
if "%FileList%"=="" set FileList=FileList.txt
if /i %1==/? goto usage
if %1==-? goto usage
if %1==-h goto usage
if %1==/h goto usage
if not exist %FileList% goto noList
echo Given list of files to find duplicates:
FOR /f %%a in (%FileList%) do echo ==^> %%a
Echo Searching for duplicate files ....
:NewDir
set dir=%1
if %1a==a set dir=.
FOR /f %%a in (%FileList%) do for /R %dir% %%b in (%%a) do if exist %%b echo %%b
shift
if %1a==a goto exit
goto NewDir
:noList
Echo I have no clue what files I should check for duplicates.
Echo (Could not find file %FileList% in current directory).
goto exit
:usage
echo.
echo Usage:
echo %0 [Dir1] [Dir2] ...
echo Example: %0 C:\Project "D:\Project Area\bin"
echo. Will search in C:\Project and "D:\Project Area\bin" for
echo. duplicate files listed in %FileList%
echo. If no arguements are provided, it searches in current directory.
echo. As usual, enclose paths that contain spaces in double-quotes.
:exit

--
Holla.


0

Response Number 2
Name: Mechanix2Go
Date: October 29, 2008 at 05:00:19 Pacific
Reply:

@echo off > results.txt
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (list.txt) do (
dir /s/b/a-d c:\%%a 2>nul >> results.txt
)


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 3
Name: klint
Date: October 30, 2008 at 06:42:01 Pacific
Reply:

@echo off
setLocal enabledelayedexpansion
set list=
for /f "delims=" %%a in (list.txt) do set list='list' "%%a"
dir /s/b %list% >results.txt


0

Response Number 4
Name: 25zerotwo
Date: November 1, 2008 at 05:58:27 Pacific
Reply:

All,

Thank you all so much for your help, i've been able to crack it now.

Extremely useful site and 'combined brain' resource.

Thanks again.

Chris


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: File search / locate Batch file.

Search with batch file www.computing.net/answers/programming/search-with-batch-file/17171.html

Batch File Search and Paste www.computing.net/answers/programming/batch-file-search-and-paste-/15699.html

Delete blank lines with batch file? www.computing.net/answers/programming/delete-blank-lines-with-batch-file/13018.html