Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 260
Nicknz125 Avatar asked Aug 23 '13 06:08

Nicknz125


People also ask

How do I list files in all subdirectories?

By default, ls lists just one directory. If you name one or more directories on the command line, ls will list each one. The -R (uppercase R) option lists all subdirectories, recursively.

Which command is used to see all the files and subfolders?

Use the ls command to display the contents of a directory. The ls command writes to standard output the contents of each specified Directory or the name of each specified File, along with any other information you ask for with the flags.

How do you list all files in a directory windows CMD?

You can use the DIR command by itself (just type “dir” at the Command Prompt) to list the files and folders in the current directory.


1 Answers

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.

like image 144
Sakthi Kumar Avatar answered Oct 06 '22 21:10

Sakthi Kumar