InUser
InUser

Reputation: 13

Dos command geetting only file names recursively

I want to list all the names of files recursively from a folder. Checked this question, but it won't help me.

dir /b "*.xml"

will give me .xml files in current folder.

dir /b /s "*.xml" 

This gives me full paths of files recursively.
However, I need to get only the file names. How can this be achieved? Could this be done using FOR? Tried some things on FOR, but not working. Please help!

Upvotes: 1

Views: 10802

Answers (1)

sjngm
sjngm

Reputation: 12861

The magic is behind the handling of variables. See the bottom of the output of for /? for more explanation.

for /f "delims=" %a in ('dir /s /b *.xml') do @echo %~nxa

Upvotes: 1

Related Questions