windows 禁止与 DIR 一起列出的目录名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7164184/
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
Suppress directory names being listed with DIR
提问by RichGK
I want to list the files in a folder but not sub-folders. DIR
enables you to list specific types of files (hidden, archive ready etc) and also only folders but I cannot see how to list only files.
我想列出文件夹中的文件而不是子文件夹。DIR
使您能够列出特定类型的文件(隐藏、存档就绪等)以及仅文件夹,但我看不到如何仅列出文件。
I need the following statement to return files for further processing, but folder names are messing things up!
我需要以下语句来返回文件以供进一步处理,但文件夹名称把事情搞砸了!
for /f %%a in ('dir /b %csvPath%') do (
)
回答by JJ.
dir /b /a-d
will give you files without directories. Note there is no space between /a-d
. The '-' says "NOT" directories.
dir /b /a-d
会给你没有目录的文件。注意 之间没有空格/a-d
。'-' 表示“非”目录。
From the dir /?
help information:
从dir /?
帮助信息:
/A Displays files with specified attributes.
attributes D Directories R Read-only files
H Hidden files A Files ready for archiving
S System files - Prefix meaning not
/B Uses bare format (no heading information or summary).
回答by Leonardo Lopez
dir /b /s /a-d
/s
lists every directory and all subdirectories containing files, and (a-d) without empty directories.
/s
列出包含文件的每个目录和所有子目录,并且 (ad) 没有空目录。
dir /b /s /a-d /p
/p
pause
/p
暂停
dir /b /s /a-d > list.txt
回答by Kev
You could use:
你可以使用:
dir /b /a-d
Which will suppress directories being listed.
这将禁止列出目录。
The /A
switch has a few other options to assist with filtering:
该/A
开关还有一些其他选项可以帮助过滤:
/A Displays files with specified attributes. attributes D Directories R Read-only files H Hidden files A Files ready for archiving S System files I Not content indexed files L Reparse Points - Prefix meaning not
回答by FishBasketGordo
Use dir /B /A-D
to get files only.
使用dir /B /A-D
只获取文件。
回答by Klox
You want the /A-D
option:
你想要的/A-D
选项:
for /f %%a in ('dir /A-D /b %csvPath%') do ( )