dirs in windows code example
Example 1: dir files windows
# For finding file use dir followed by string matching file name or regex
# pattern and add "/s" for searching recursively in subfolders:
dir /s "regex_or_file_name"
# For finding file contained in a searched directory use "/b":
dir /b "directory_name"
# Use respectively '/a-d' or '/ad' for finding only files or only folders.
Example 2: dos dir
dir *.txt *.doc # filter by extension (both doc and txt)
dir /a:-d # files only (no subfolders)
dir /s # current directory and subfolders content
dir /s /a:-d # files only (including subfolders)
dir > myfile.txt # stored in myfile.txt (dir /s > myfile.txt with subfolders)
dir /o:[sortorder] # example: dir /o:-s (sort by decreasing size)
N : By name (alphabetic).
S : By size (smallest first).
E : By extension (alphabetic).
D : By date/time (oldest first).
- : Prefix to reverse order.