What's the Windows command-line to list all folders without current and parent directories? Something similar to ls -A
in Linux
1 Answer
ls -A
lists all files and directories and not just folders
It's a lot trickier to do that in cmd. dir /ah
will list files/folders that have the hidden attribute so you'll miss files that have only system attribute. You'll need to get system files separately with dir /as
, and also normal folders with dir
because folders without any attributes won't be displayed in dir /ah
and dir /as
. For more information run dir /?
or read the dir
documentation
Then comes the issue of combining the result. In Windows 10 sort
has a new /unique
flag so you can use the following command to get the desired result
(dir /ah & dir /as & dir) | sort /unique
You can also use (dir /b /ah & dir /b /as & dir /b) | sort /unique
to get a saner result. In older Windows you're on your own to remove the duplicate entries
It's better to use PowerShell. Just run either of these
Get-ChildItem -Force
Get-ChildItem -Attributes Directory,Hidden,System
or their abbreviated versions
ls -Fo
ls -At D,H,S
You can call them from cmd like this powershell -Command "Get-ChildItem -Attributes Directory,Hidden,System"
or powershell -c "ls -Fo"
. For more information about the command read Get-ChildItem
dir "c:\" /s /ah /b
and see if that does what you want for listing the hidden ones only.dir /b
is the closest tols -A
but the output will be 1 file or directory per line not as unix with multiple entries on enach linedir /ah
will only list hiddens files and not system files without hidden attribute