How to list all files in a directory / subdirectory without a CMD path name?

I have a directory containing many subdirectories. Inside these subdirectories are the .asf, .jpg, and .txt files. I would like to list all * .asf files in a directory and subdirectory, but without a path name.

So basically I want to make the dir / s command, but not show the full path. Is there any way to do this.

+7
windows directory cmd batch-file dir
source share
4 answers

Very late, but may be helpful to someone. I assume he asks for this command with one line

forfiles /m *.asf /s >d:\Hitendra.Txt

here, as you all know after that (>) . I save the result to drive D of my computer using the file name Hitendra.Txt

+7
source share

Check:

 FORFILES /S /C "CMD /C ECHO @relpath" 
+4
source share

try this on the cmd command line:

 for /r %a in (*.asf) do @echo %~tza %~nxa 

only name:

 for /r %a in (*.asf) do @echo %~nxa 
+3
source share

You can try

 dir /s | findstr .asf 

Edit: I think this will help. This is my test.bat

 @echo off for /f "usebackq TOKENS=*" %%i in (`dir /s /b *.txt`) do echo %%~nxi pause 

/f usebackq says that whatever backquotes is executed as a dos command

TOKENS=* also parses file names with spaces.

echo %%~nxi - n only file names are listed, and x is only the extension. Combining both displays the file name and extension.

Edit: usebackq not required, a single quote can be used instead.

+3
source share

All Articles