禁止使用DIR列出的目录名称

我想列出文件夹中的文件,但不是子文件夹。 DIR使您可以列出特定types的文件(隐藏,存档准备等),也只有文件夹,但我看不出如何只列出文件。

我需要以下语句来返回文件进行进一步处理,但文件夹名称正在搞砸!

 for /f %%a in ('dir /b %csvPath%') do ( ) 

dir /b /ad会给你没有目录的文件。 请注意/ad之间没有空格。 “ – ”表示“NOT”目录。

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). 

使用dir /B /AD来获取文件。

 dir /b /s /ad 

/s列出每个目录和所有包含文件的子目录,(ad)没有空目录。

 dir /b /s /ad /p 

/p暂停

 dir /b /s /ad > list.txt 

你可以使用:

 dir /b /ad 

这将抑制目录被列出。

/A开关有几个其他选项来协助过滤:

 / A显示具有指定属性的文件。
属性D目录R只读文件
              H隐藏的文件A准备归档的文件
              S系统文件I不包含索引文件
              L重新分析点 - 前缀的意思不是

你想要/AD选项:

 for /f %%a in ('dir /AD /b %csvPath%') do ( )