DIR – Windows CMD Command

Display a list of files and subfolders.

The switches above can be preset by adding them to an environment variable called DIRCMD.
For example SET DIRCMD=/O:N /S

Override any preset DIRCMD switches by prefixing the switch with –
For example DIR *.* /-S

Sorting

The default Sort Order, if you don’t specify anything with /O, on an NTFS drive will be in sort-of-alphabetical order or on a FAT USB thumb drive, then the order will be based on the order in which files were created and deleted and the lengths of their names.

Upper and Lower Case filenames:

Filenames longer than 8 characters – will always display the filename with the mixed case as entered.
Filenames shorter than 8 characters – can display the filename in upper or lower case – this can vary from one client to another (registry setting)

Listing the full path

The command DIR /b will return just a list of filenames, when displaying subfolders with DIR /b /s the command will return a full pathname.

If you want to list the full path without including subfolders, use the FOR command as in this example script.

Errorlevels

If the file(s) were successfully listed %ERRORLEVEL% = 0
If the file was not found or bad parameters are given %ERRORLEVEL% = 1

All file sizes are shown in bytes.

DIR is an internal command.

You may also like...

Leave a Reply

Your email address will not be published.