Page 1 of 1

display full path when only certain files are searched

Posted: 02 Apr 2010 06:47
by jamesfui
hi every dostips scripters !
how do you display ONLY the full path of the certain files search??
for example,

random_list.txt
------------------content------------------
jan10reports.doc
once a girl.avi
smiley.jpg
new robots.pdf
.....etc
------------------end content--------------


search_list.txt
------------------content------------------
smiley.jpg
new robots.pdf
------------------end content--------------



script.bat
----------------code start------------------
@echo off
for /f %%a in ('findstr /g:search_list.txt random_list.txt) do dir /s /b %%a > fullpath.txt

^ i know the above code is wrong, miss out the directory to search on too!
need help with the batch script.bat

so that the result will be like below,

fullpath.txt
------------------content---------------------
c:\pictures\2010\msn\smiley.jpg
d:\technology\2010\books\new robots.pdf

------------------content end-----------------


thanks!!! :)

Re: display full path when only certain files are searched

Posted: 02 Apr 2010 07:17
by !k

Code: Select all

for /f "delims=" %%a in ('findstr /g:search_list.txt random_list.txt') do dir /s /b "%%~fa" > fullpath.txt

Use /? key for help.

Re: display full path when only certain files are searched

Posted: 03 Apr 2010 05:36
by jamesfui
for /f "delims=" %%a in ('findstr /g:search_list.txt random_list.txt') do dir /s /b "%%~fa" >> fullpath.txt

it works well, only we need to add in one more redirection > to the >> fullpath.txt shown above in order to work..

thanks :D

Re: display full path when only certain files are searched

Posted: 05 Apr 2010 09:52
by avery_larry
If the directory is large, it might be more efficient to build the list of files first using findstr as you have done, but then instead of a dir /s on each match found, just put that list of files into another file and use findstr on a single dir /s.

Something like (untested):

for /f "delims=" %%a in ('findstr /g:search_list.txt random_list.txt') do echo "%%~fa" >> search_list2.txt
dir /s /b | findstr /g:search_list2.txt