Sort files and directories
dir /ox
sorts the listed files. x
specifies the sorting criteria:
n | alphabetically |
e | filename extension |
s | size |
d | modification time and date |
g | show group directories first |
If the sorting criteria letter is prepended with a dash, the sorting order is reversed. The following command shows the newest files/directories first:
C:\Users\Rene> dir /o-d
Include / exclude files with specific attributes
/Ax
includes, /A-x
excludes files with a given attribute x
. /A
shows all files, no matter what their attributes.
The possible values for x
are:
d | Directories |
h | Hidden files |
s | System files |
l | Reparse points |
r | Read-only files |
a | Files ready for archiving |
i | Not content indexed files |
o | Offline files |
Environment variable DIRCMD
It might be set, for example, to /ogn /a
to always show the directories first and sort by file/directory name and to show all (including hidden) files.
Recursively searching for files that match a wildcard
In order to search for files that match a given wildcard in and below the current directory, the /s
option must be used:
C:\Users\Rene> dir /s *quarter*.xls*
However, unfortunately, I find the output quite unreadable because it is cluttered with directory names and file attributes that I am (usually) not interested in. The option /b
(bare format) only prints (absolute) filenames, which makes the reading of the result much easier:
C:\Users\Rene> dir /s /b *quarter*.xls*
In
PowerShell, the effect of
dir /s /b
can be achieved by using a variant of a
pipeline like so:
PS C:\Users\Rene> get-childItem -recurse -filter *quarter*.xls* | select-object fullname