24

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.

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 (
)
Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
RichGK
  • 550
  • 3
  • 10
  • 19

5 Answers5

49

dir /b /a-d will give you files without directories. Note there is no space between /a-d. The '-' says "NOT" directories.

From the dir /? help information:

  /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).
JJ.
  • 5,425
  • 3
  • 26
  • 31
8
dir /b /s /a-d

/s lists every directory and all subdirectories containing files, and (a-d) without empty directories.

dir /b /s /a-d /p

/p pause

dir /b /s /a-d > list.txt
user3335966
  • 2,673
  • 4
  • 30
  • 33
3

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          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
Kev
  • 118,037
  • 53
  • 300
  • 385
2

Use dir /B /A-D to get files only.

FishBasketGordo
  • 22,904
  • 4
  • 58
  • 91
0

You want the /A-D option:

for /f %%a in ('dir /A-D /b %csvPath%') do ( )
Klox
  • 931
  • 12
  • 21