I need to just list file names in a maze of subdirectories. so I tried using:
dir /b/s
with /b for bare file name and /s for subdirectories
but even with /b, this gives the file name plus path. How can I get just the file names?
Thank you for your help.
Mr. Bob
Show file names without paths
Moderator: DosItHelp
Re: Show file names without paths
From a command prompt. Double the percent signs if you run this from a batch file.
Code: Select all
for /F "delims=" %G in ('dir /a-d /b /s') do echo %~nxG
Re: Show file names without paths
Squashman,
Thank you! It's all gibberish to me, but it does what I needed at the command line.
Should this work in a batch file?
Mr Bob
Thank you! It's all gibberish to me, but it does what I needed at the command line.
Should this work in a batch file?
Code: Select all
@Echo off
cd c:\directory1
for /F "delims=" %%G in ('dir /a-d /b /s') do echo %%~nxG > C:\Users/MrBob\Documents\files.txt
cd c:\directory2
for /F "delims=" %%G in ('dir /a-d /b /s') do echo %%~nxG >> C:\Users\MrBob\Documents\files.txt
Mr Bob
Re: Show file names without paths
Just put the directory name in with the DIR command.
Code: Select all
@Echo off
for /F "delims=" %%G in ('dir c:\directory1\ /a-d /b /s') do echo %%~nxG > C:\Users/MrBob\Documents\files.txt
for /F "delims=" %%G in ('dir c:\directory2\ /a-d /b /s') do echo %%~nxG >> C:\Users\MrBob\Documents\files.txt
Re: Show file names without paths
Just adding another option.
Code: Select all
@echo off
(
for /r "c:\directory1" %%a in (*) do echo %%~nxa
for /r "c:\directory2" %%a in (*) do echo %%~nxa
)>"%userprofile%\Documents\files.txt"