I ran into a little snag trying to get only the filenames (no extensions or file paths) recursively.This worked for me in the root folder:

dir /b

But when i added /s to scan recursively i also got file paths before filenames which i do not want. Is there a way to get bare filenames from all subfolders in a directory?

Im on Windows 7 x64 I'd rather use regular command prompt not PS or VBS

link|improve this question

58% accept rate
feedback

2 Answers

Try this:

for /f %a in ('dir /b') do @echo %~na

More information on how for works and what it's doing, type for /?

link|improve this answer
This almost works but there's a big problem.It only outputs the first word of a filename.If a filename is for example "my vacation image 1" then it only outputs "my" – TMRW Jun 8 '11 at 4:10
try this: for /f "delims=|" %a in ('dir /b') do @echo %~na. By default the /f parameter of FOR will tokenize on spaces. Setting the token to a character that shouldn't appear in file/directory names will give you the entire name including spaces. – Scott McKinney Nov 8 '11 at 22:17
feedback

Use the following command:

dir /b /a /s
  • /b strips the date and other details from the output
  • /a only outputs the filename, no paths
  • /s enables a recursive directory listing

If you need to save the output to a file, you can use:

dir /b /a /s >> list_of_names.txt

EDIT Actually the above solution doesn't reach the original question's goals. One thing I did notice from the question is that the post asks for recursive listing. which the other answer lacks so I think adding "/s" in the other answerer's answer will do the trick

for /f %a in ('dir /b /s') do @echo %~na
link|improve this answer
Could you explain this? To me it makes little sense. – Simon Sheehan Nov 8 '11 at 23:27
This doesn't work, /a doesn't work like that - it's a filter for which type of files you want to list. It doesn't strip the path from the filename when doing a recursive directory listing. – Gareth Nov 9 '11 at 2:28
edited the answer; and just got my hands on a windows box again, I think this time should do it (win732bit) – Nik Nov 9 '11 at 5:27
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.