How do I recursively list filenames (only) in DOS/Windows?

21

13

Possible Duplicate:
Get bare file names recursively in command prompt

I would like to recursively list all files in a directory, showing filenames only (without extensions and without the full paths). I'm using Windows/DOS.

The closest I could get with dir was dir /s /b, but it lists full paths and also shows the extensions.

Well, perhaps I could live with the extensions, but I must get rid of the paths!

Any ideas?

David B

Posted 2011-10-07T20:07:35.553

Reputation: 1 974

Question was closed 2011-10-08T11:43:18.117

1Which version of windows? – OldWolf – 2011-10-07T20:21:14.743

@OldWolf: XP. I prefer not to use any third-party software/ – David B – 2011-10-07T20:24:09.910

Answers

28

cd /d C:\Path\To\Source\Folder
for /r %i in (*) do @echo %~ni

If you need the list saved to a file, append >> C:\Path\To\list_file.txt to the end of the for command.

If you end up wanting the extensions, change %~ni to %~nxi

To use in a batch file, change all the % to %%

afrazier

Posted 2011-10-07T20:07:35.553

Reputation: 21 316

6If you need path and name and extension, change %~ni to %~pnxi – Deep – 2014-08-01T13:11:37.747

this works but it doesn't show hidden files. How can I also see the hidden files? – ala – 2015-05-02T09:01:55.177

@ala: If you want to show hidden files, you'll need to use something like David Remy's answer only with the appropriate flags passed to the dir command.

– afrazier – 2015-05-02T14:00:28.667

8

If you are willing to load powershell, this command should do it.

get-childitem "d:\acc" -recurse|foreach {$_.Basename}

uSlackr

Posted 2011-10-07T20:07:35.553

Reputation: 8 755

5

Doing something like the following should get you what you want:

@for /f "delims=" %a in ('Dir /s /b %systemdrive%') do echo %~na

Just pipe the output to a file and use it from there if needed.

David Remy

Posted 2011-10-07T20:07:35.553

Reputation: 1 899

3

Don't know if you'd consider it a 3rd party software or not since it's form Microsoft and ships with 7, but powershell will solve most of your problem pretty easily. If you haven't already installed it, it's available for XP on Microsoft's site.

Get-ChildItem -path "C:\Program Files\" -recurse | foreach ($_) {
    write $_.name
}

OldWolf

Posted 2011-10-07T20:07:35.553

Reputation: 2 293