Get bare file names recursively in command prompt

command linefilenamesrecursive

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

Best Answer

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
Related Question