Use Dir Command for List of Filenames Only
Moderator: DosItHelp
Use Dir Command for List of Filenames Only
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
Regards...John
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Use Dir Command for List of Filenames Only
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
Just a correction for the above solution, (which lists folder names too)!
…and a few alternatives.three not using the Dir command
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
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
Thanks for the replies. Forgive the newbie question, but where can I download the 'For' command?
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Use Dir Command for List of Filenames Only
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
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.
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Use Dir Command for List of Filenames Only
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.
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
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:
Code: Select all
for /?