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!!!
display full path when only certain files are searched
Moderator: DosItHelp
Re: display full path when only certain files are searched
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
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
it works well, only we need to add in one more redirection > to the >> fullpath.txt shown above in order to work..
thanks
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
Re: display full path when only certain files are searched
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
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