Page 1 of 1
Use Dir Command for List of Filenames Only
Posted: 11 Sep 2016 20:36
by johnbil
I need to make a list of all files, all types, in a folder and its subfolders. I don't want the folder and subfolder names to appear in the list, just the file names. Does any one know if this can be done and if so, what command options I should use?
Regards...John
Re: Use Dir Command for List of Filenames Only
Posted: 11 Sep 2016 22:24
by ShadowThief
Code: Select all
for /f "delims=" %A in ('dir /b /S') do echo %~nxA
Obviously, if you're doing this from a script instead of the command line, use %% instead of %.
Re: Use Dir Command for List of Filenames Only
Posted: 12 Sep 2016 10:38
by Compo
Just a correction for the above solution,
(which lists folder names too)!
Code: Select all
For /F "Delims=" %A In ('Dir/B/S/A-D') Do @Echo=%~nxA
…and a few alternatives.
Code: Select all
For /R "%UserProfile%\Desktop" %I In (*) Do @Echo=%~nxI
three not using the
Dir command
Code: Select all
ForFiles /P "%UserProfile%\Desktop" /S
Code: Select all
For /F "Delims=" %I In ('Where /R "%UserProfile%\Desktop" *.* 2^>Nul') Do @Echo=%~nxI
Code: Select all
For /F "Delims=" %I In ('RoboCopy /L /S /NS /NC /NP /NDL /NJH /NJS "%UserProfile%\Desktop" null *.*') Do @Echo=%~nxI
Re: Use Dir Command for List of Filenames Only
Posted: 12 Sep 2016 11:59
by johnbil
Thanks for the replies. Forgive the newbie question, but where can I download the 'For' command?

Re: Use Dir Command for List of Filenames Only
Posted: 12 Sep 2016 12:05
by ShadowThief
johnbil wrote:Thanks for the replies. Forgive the newbie question, but where can I download the 'For' command?

it's built into batch.
Re: Use Dir Command for List of Filenames Only
Posted: 13 Sep 2016 00:25
by johnbil
Not sure, but don't I need a For.exe/For.com file somewhere on my Windows 7 system? I keep getting a 'file not found' error message.
Re: Use Dir Command for List of Filenames Only
Posted: 13 Sep 2016 00:37
by ShadowThief
For is a command, it isn't a program. It's impossible for it to not be on your system, since it's part of your system.
What are you doing with the list of files? If you're just displaying them, there's no reason for you to be getting that error message. If you're doing things with a file that's in a subdirectory and you aren't in that subdirectory, the file isn't found because it's looking for a file with that name in the current directory instead of the directory where the file actually is.
Re: Use Dir Command for List of Filenames Only
Posted: 13 Sep 2016 09:23
by Squashman
johnbil wrote:Not sure, but don't I need a For.exe/For.com file somewhere on my Windows 7 system? I keep getting a 'file not found' error message.
It is an internal cmd. Just like CD, CALL, COPY, DEL, ETC.....
Open up a cmd prompt and type: