windows 如何在没有路径名CMD的情况下列出目录/子目录中的所有文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18396761/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:48:43  来源:igfitidea点击:

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

windowsbatch-filedirectorycmddir

提问by Nicknz125

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.

我有一个包含许多子目录的目录。在这些子目录中加载了 .asf、.jpg 和 .txt 文件。我想列出目录和子目录中的所有 *.asf 文件,但没有路径名。

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

所以基本上我想执行 dir /s 命令但不显示完整路径名。有没有办法做到这一点。

回答by Hitendra

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

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

众所周知,在此之后,(>)我将结果保存在我计算机的 D 驱动器中,文件名为 Hitendra.Txt

回答by LS_???

Check:

查看:

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

回答by Endoro

try this on the cmd shell prompt:

在 cmd shell 提示符下试试这个:

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

only the name:

只有名字:

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

回答by Sakthi Kumar

You can try

你可以试试

dir /s | findstr .asf

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

编辑:我认为这会有所帮助。这是我的test.bat

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

/f usebackqsays that whatever inside backquotes are executed as dos command

/f usebackq说反引号内的任何内容都作为 dos 命令执行

TOKENS=*parses file names with spaces also.

TOKENS=*也解析带有空格的文件名。

echo %%~nxi- nlists out only the file names and xlists out only the extension. Combining both displays file name and extension.

echo %%~nxi-n仅列出文件名并x仅列出扩展名。结合两者显示文件名和扩展名。

Edit: usebackqis not necessary instead single quote can be used.

编辑: usebackq不是必需的,而是可以使用单引号。