Home > database >  How to list sub directory first and then parent directory in cmd?
How to list sub directory first and then parent directory in cmd?

Time:12-07

How to list subdirectory first and then parent directory in command prompt. Child to parent traverse instead of Parent to child

Lets, say I've folder 'Income' and sub folder 'Tax', 'Tax' contains sub Folder 'Report' and need list as deepest folder first

D:/Income/Tax/Report
D:/Income/Tax/
D:/Income/

Used dir /A:D/S/B/O:-D command still it list as Parent to Child

CodePudding user response:

Piping that command to reverse sort seems to help?

Microsoft Windows [Version 10.0.19043.1348]
(c) Microsoft Corporation. All rights reserved.

C:\WINDOWS\system32>d:

D:\>dir /A:D/S/B/O:-D | sort /R
// ... removed extra
D:\preload\RM_Reserve\system.sav\FactoryUpdate\FU_6_277229_20171201_200A1
D:\preload\RM_Reserve\system.sav\FactoryUpdate\FU_6_260181_20170916_100A1
D:\preload\RM_Reserve\system.sav\FactoryUpdate
D:\preload\RM_Reserve\system.sav
D:\preload\RM_Reserve\SWSetup\sw_ver
D:\preload\RM_Reserve\SWSetup
D:\preload\RM_Reserve
D:\preload\RM_PATCH
D:\preload\FactoryUpdate\UserDLSoftpaq
D:\preload\FactoryUpdate
D:\preload
D:\Income\Tax\Reports         // Listed here
D:\Income\Tax
D:\Income
D:\EFI\Microsoft\Boot\zh-tw
D:\EFI\Microsoft\Boot\zh-hk
D:\EFI\Microsoft\Boot\zh-cn
D:\EFI\Microsoft\Boot\tr-tr
D:\EFI\Microsoft\Boot\sv-se
// ... removed extra
  • Related