Nicknz125
Nicknz125

Reputation: 91

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

I Have a directory containing many subdirectories. Within these subdirectories are loads of .asf, .jpg, & .txt files. I would like to list all *.asf files within the directory and subdirectory but without the pathname.

So basically I want to do the dir /s command but not display the full pathname. Is there anyway to do this.

Upvotes: 9

Views: 52088

Answers (4)

Hitendra
Hitendra

Reputation: 129

Very late but may be useful to someone. I guess he is asking for this one line command

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

here as you all know after this (>) I'm saving result in D drive of my computer with a file name Hitendra.Txt

Upvotes: 12

Sakthi Kumar
Sakthi Kumar

Reputation: 3045

You can try

dir /s | findstr .asf

Edit: I think this would 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 inside backquotes are executed as dos command

TOKENS=* parses file names with spaces also.

echo %%~nxi - n lists out only the file names and x lists out only the extension. Combining both displays file name and extension.

Edit: usebackq is not necessary instead single quote can be used.

Upvotes: 4

LS_ᴅᴇᴠ
LS_ᴅᴇᴠ

Reputation: 11151

Check:

FORFILES /S /C "CMD /C ECHO @relpath"

Upvotes: 6

Endoro
Endoro

Reputation: 37569

try this on the cmd shell prompt:

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

only the name:

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

Upvotes: 5

Related Questions