4

Continuing this answer from How can I list directories and their sizes in command prompt?

How to list directories recursively with size using PowerShell?

user1970832
  • 151
  • 1
  • 5
  • What are you trying to exactly? List and Sort by size and have re-list them every 30 seconds if the size changes? Can you be more specific? – Narzard Sep 02 '16 at 19:04
  • i just want to list directory name along with size recursively. something similar to unix command `du -h` – user1970832 Sep 02 '16 at 19:20
  • this command prints overall usage of current directory- `powershell -noprofile -command "ls -r|measure -s Length"` but i want to print name with size. – user1970832 Sep 02 '16 at 19:23

1 Answers1

5

How to list directories recursively with size using PowerShell?

If it's really just a recursive list you need including the file size for each file then give ForFiles a shot using the syntax below which happens to work with PowerShell as well as command line, and it has a very similar output to the Unix du -h command as you indicate you need in a comment.

Universal PowerShell and Command Line Method

Output is similar to Unix du -h but you could format further if needed.

FORFILES /S /M * /C "CMD /C ECHO @FSIZE          @PATH"

Further Resources

Vomit IT - Chunky Mess Style
  • 40,038
  • 27
  • 84
  • 117
  • thank you so much. it list files and directories both, i found what i was looking for! – user1970832 Sep 02 '16 at 19:43
  • How to use this solution for UNC paths? – kurp Nov 07 '18 at 12:03
  • 1
    @kurp Unfortunately forfiles doesn't support UNC paths that I know of but as a workaround you can first run `PUSHD "\\servername\sharename"` then run `FORFILES /S /M * /C "CMD /C ECHO @FSIZE @PATH"`, and when it's done or on the next line run `POPD` and this will essentniallys change to the UNC path and run the command for you and create an arbitrary network mapping and use a drive letter for you then unmap it when done with `popd` – Vomit IT - Chunky Mess Style Nov 07 '18 at 14:03