Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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.

@echo off > results.txt
setLocal EnableDelayedExpansionfor /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

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

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

![]() |
![]() |
![]() |

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