display full path when only certain files are searched

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jamesfui
Posts: 50
Joined: 27 Mar 2010 23:00

display full path when only certain files are searched

#1 Post by jamesfui » 02 Apr 2010 06:47

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!!! :)

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: display full path when only certain files are searched

#2 Post by !k » 02 Apr 2010 07:17

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.

jamesfui
Posts: 50
Joined: 27 Mar 2010 23:00

Re: display full path when only certain files are searched

#3 Post by jamesfui » 03 Apr 2010 05:36

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

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

Re: display full path when only certain files are searched

#4 Post by avery_larry » 05 Apr 2010 09:52

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

Post Reply