List out but excluding same filenames from subfolders!!

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

List out but excluding same filenames from subfolders!!

#1 Post by jamesfui » 17 Apr 2010 03:33

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

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

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

#2 Post by avery_larry » 19 Apr 2010 10:01

for /f "delims=" %%a in ('dir /a-d /b "c:\documents\*.doc"') do echo c:\documents\%%a>>list.txt

Post Reply