1

What's the Windows command-line to list all folders without current and parent directories? Something similar to ls -A in Linux

4
  • dir /ah lists hidden folders / files where you are.
    – John
    May 1, 2020 at 23:45
  • Give a try dir "c:\" /s /ah /b and see if that does what you want for listing the hidden ones only. May 1, 2020 at 23:51
  • dir /b is the closest to ls -A but the output will be 1 file or directory per line not as unix with multiple entries on enach line
    – DavidPostill
    May 1, 2020 at 23:53
  • @John dir /ah will only list hiddens files and not system files without hidden attribute
    – phuclv
    May 1, 2020 at 23:54

1 Answer 1

1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .