Solved Search for file - script

June 3, 2012 at 11:40:56
Specs: Windows 7
Hey there!
Trying to make a script that searches the local computer for filenames (with wildcards) from a textfile (filenames.txt) and types the result in a logfile.txt.

So far I got this:

@echo off
for /f "tokens=* delims= " %%a in (filenames.txt) do (
if exist %%a echo %%a found on %computername% >> logfile.txt
)

That works fine but I would like the script to search for ALL files for every hit in "filenames.txt".
If I have a file called hello12433.txt and hello34#.exe it should report both, if the filename is hello*.* and then continue on the next filename in filenames.txt

Hope I explained it good enough =).

Anyone?


See More: Search for file - script

Report •

#1
June 3, 2012 at 19:46:56
:: ===== script starts here ===============
::
:: knog.bat Mon 04-06-2012 9:38:46.84
@echo off > newfile & setLocal enableDELAYedeXpansioN

for /f "tokens=* delims= " %%a in (filelist) do (
dir/b/s "\%%a" > nul && >> newfile echo %%a found on %computername%
)

goto :eof

::====== script ends here =================


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
June 3, 2012 at 23:59:38
Thanks!!

One more question...
... Is it possible to search for a file in a specific directory?

When I put in C:\Temp\We.* in the filelist I get error:
" Wrong syntax..."

Much appreciated!


Report •

#3
June 4, 2012 at 01:34:00
✔ Best Answer
:: ===== script starts here ===============
::
:: knog.bat Mon 04-06-2012 9:38:46.84
@echo off > newfile & setLocal enableDELAYedeXpansioN

copy filelist \ > nul
pushd \
for /f "tokens=* delims= " %%a in (filelist) do (
dir/b/s "%%a" > nul 2>nul && >> newfile echo %%a found on %computername%
)

goto :eof

::====== script ends here =================


=====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions

#4
June 7, 2012 at 05:09:53
Great,
but it seems like the script stops as soon it finds the first file in the filelist. It doesnt continue when finding the first file.
Or am I doing something wrong?


Report •

#5
June 7, 2012 at 06:50:14
It doesn't stop for me.


=====================================
Life is too important to be taken seriously.

M2


Report •

#6
June 7, 2012 at 07:07:40
True,
I did something wrong :)

Is it hard to put in in "newfile" where the file was found? For example if I search for yeah*.txt and it is found in C:\temp, I would like the logfile to say "%%a (filename) found in C:\temp"


Report •

Ask Question