Page 1 of 1

List out but excluding same filenames from subfolders!!

Posted: 17 Apr 2010 03:33
by jamesfui
hi batch scripters!! :(
i need to list out the jan.doc in full path but doesn't want to include the subfolders with the same filename..
for example,
c:\documents\report\2008\jan.doc
c:\documents\report\2009\jan.doc
c:\documents\report\jan.doc

below is my scripts but doesn't output the desire result,
dir /s /b c:\documents\*.doc> list.txt

it outputs like below,
list.txt (not this)
--------------------content-------------------
c:\documents\report\2008\jan.doc
c:\documents\report\2009\jan.doc
c:\documents\report\jan.doc

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

and if my remove the /s in my scripts, it will output as below,
list.txt (not this)
-----------------content---------------------
jan.doc

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


all i need is just like below,
list.txt
-----------------content---------------------
c:\documents\report\jan.doc <- like this

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

include the full path of the files in that folder but excluding
the files in the subfolders with the same filenames!!!

any idea!! thanks :D

Re: List out but excluding same filenames from subfolders!!

Posted: 19 Apr 2010 10:01
by avery_larry
for /f "delims=" %%a in ('dir /a-d /b "c:\documents\*.doc"') do echo c:\documents\%%a>>list.txt