Deny directory names listed in DIR

I want to list files in a folder, but not subfolders. DIR allows you to specify specific file types (hidden, ready-made archives, etc.), as well as folders only, but I don’t see how to list only files.

I need the following statement to return files for further processing, but the folder names are confused!

 for /f %%a in ('dir /b %csvPath%') do ( ) 
+7
windows cmd
Aug 23 '11 at 16:15
source share
5 answers

dir /b /ad will provide you files without directories. Note that there is no space between /ad . "-" says "NOT" directories.

From the reference 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). 
+11
Aug 23 '11 at 16:20
source share

Use dir /B /AD only for receiving files.

+1
Aug 23 '11 at 16:21
source share
 dir /b /s /ad 

/s lists each directory and all subdirectories containing files, and (ad) without empty directories.

 dir /b /s /ad /p 

/p pause

 dir /b /s /ad > list.txt 
+1
Aug 31 '15 at 10:30
source share

You can use:

 dir /b /ad 

Which will suppress the list of directories.

The /A switch has several other options to help filter:

 / 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
0
Aug 23 '11 at 16:20
source share

You need the /AD option:

 for /f %%a in ('dir /AD /b %csvPath%') do ( ) 
0
Aug 23 '11 at 16:21
source share



All Articles