Change Default Sorting Order of 'dir' Command in Windows
7,117
Solution 1
The %DIRCMD%
environment variable can be used to specify defaults for dir
.
Solution 2
Try opening Control Panel > System > Advanced tab > Environment Variables.
Create the system variable DIRCMD
and assign the value /a /c /p /x /o:gen
Related videos on Youtube
Author by
Larssend
Updated on September 18, 2022Comments
-
Larssend almost 2 years
By default, Windows'
dir
command sorts files and directories alphabetically without grouping. The result is files and directories appear interleaved with one another. Sample output:F:\Dev Kits>dir Volume in drive F is Buffer II Volume Serial Number is E039-C389 Directory of F:\Dev Kits 07/26/2011 05:02 AM <DIR> . 07/26/2011 05:02 AM <DIR> .. 10/08/2009 05:41 PM 408,330 Bat To Exe Converter 1.5.zip 07/26/2011 04:53 AM <DIR> Boost 10/27/2009 09:37 PM 20,248,963 CodeBlocks 8.02 Mingw.exe 02/20/2010 12:26 AM 1,251,993 CodeBlocks Manual.pdf 04/18/2010 05:39 PM 610,769 Dependency Walker 2.2.6000 x86.zip 05/29/2010 04:37 PM 4,387 Dev Kits.sha2 07/26/2011 04:59 AM <JUNCTION> iOS SDK 01/31/2011 09:40 PM 35,213,765 MinGW GCC 4.4.0_1.zip 11/17/2009 01:41 AM 2,834,808 Notepad++ Portable 5.5.1.exe 01/07/2010 06:04 PM 3,860,528 Notepad++ Portable 5.6.4.exe 11/17/2009 12:31 AM 261,563 Notepad2 4.0.23.zip 03/08/2011 07:07 PM 9,932,872 Opera Mobile 10.1 Emulator.exe 05/25/2010 08:46 AM 162,506 PC-Police.zip 04/05/2010 10:37 PM <DIR> Python 07/26/2011 05:02 AM <DIR> Qt Framework and SDK 04/05/2010 10:35 PM <DIR> Series 80 SDK 07/26/2011 04:52 AM <DIR> Symbian SDK 07/26/2011 05:00 AM <DIR> Unit Testing 07/26/2011 04:51 AM <JUNCTION> Visual Studio Tools 04/07/2011 04:51 PM 17,349,072 Win32 OpenSSL 1.0.0d.exe 02/19/2010 11:05 PM 397,056 Win32pp Compiled Samples.zip 07/26/2011 04:53 AM <DIR> Windows Phone SDK 07/26/2011 04:52 AM <DIR> Windows Platform SDK 11/14/2009 07:49 PM 12,811,696 wxMSW 2.8.10 Setup.exe 11/15/2009 01:34 AM 2,808 wxMSW Installation.txt 15 File(s) 105,351,116 bytes 12 Dir(s) 1,346,224,128 bytes free
Adding the
/OGN
switch makes the output much more organized:F:\Dev Kits>dir /ogn Volume in drive F is Buffer II Volume Serial Number is E039-C389 Directory of F:\Dev Kits 07/26/2011 05:02 AM <DIR> . 07/26/2011 05:02 AM <DIR> .. 07/26/2011 04:53 AM <DIR> Boost 07/26/2011 04:59 AM <JUNCTION> iOS SDK 04/05/2010 10:37 PM <DIR> Python 07/26/2011 05:02 AM <DIR> Qt Framework and SDK 04/05/2010 10:35 PM <DIR> Series 80 SDK 07/26/2011 04:52 AM <DIR> Symbian SDK 07/26/2011 05:00 AM <DIR> Unit Testing 07/26/2011 04:51 AM <JUNCTION> Visual Studio Tools 07/26/2011 04:53 AM <DIR> Windows Phone SDK 07/26/2011 04:52 AM <DIR> Windows Platform SDK 10/08/2009 05:41 PM 408,330 Bat To Exe Converter 1.5.zip 10/27/2009 09:37 PM 20,248,963 CodeBlocks 8.02 Mingw.exe 02/20/2010 12:26 AM 1,251,993 CodeBlocks Manual.pdf 04/18/2010 05:39 PM 610,769 Dependency Walker 2.2.6000 x86.zip 05/29/2010 04:37 PM 4,387 Dev Kits.sha2 01/31/2011 09:40 PM 35,213,765 MinGW GCC 4.4.0_1.zip 11/17/2009 01:41 AM 2,834,808 Notepad++ Portable 5.5.1.exe 01/07/2010 06:04 PM 3,860,528 Notepad++ Portable 5.6.4.exe 11/17/2009 12:31 AM 261,563 Notepad2 4.0.23.zip 03/08/2011 07:07 PM 9,932,872 Opera Mobile 10.1 Emulator.exe 05/25/2010 08:46 AM 162,506 PC-Police.zip 04/07/2011 04:51 PM 17,349,072 Win32 OpenSSL 1.0.0d.exe 02/19/2010 11:05 PM 397,056 Win32pp Compiled Samples.zip 11/14/2009 07:49 PM 12,811,696 wxMSW 2.8.10 Setup.exe 11/15/2009 01:34 AM 2,808 wxMSW Installation.txt 15 File(s) 105,351,116 bytes 12 Dir(s) 1,346,224,128 bytes free
Question: Is it possible to make
dir
use the/ogn
switch by default? -
Larssend almost 13 yearsI added DIRCMD environment variable with /ogn as value via System Properties but it doesn't seem to have effect. Setting it using 'set dircmd=/ogn' works, but it's reset every time I open a new CMD. Any ideas?
-
Naidim almost 13 years@Larssend: If you are using Vista onwards (or add the command on XP and earlier), you can set it persistently for all users with
setx DIRCMD "/ogn" /m
. -
Larssend almost 13 years@all: The DIRCMD took effect immediately on new command prompt session after I closed System Properties on my laptop, but my desktop still refuses to recognize the new variable. So I think there's something wrong with the desktop setup. That's a different problem, so I'm marking this one solved. Thank you all.
-
surfasb almost 13 yearsAhh, the old school %dircmd%.