Forum Discussion
Sandeepkv3003
Oct 05, 2021Copper Contributor
How to get filesize in a folder with single command?
I am relatively new to Powershell and trying to get to hands on experience of learning it. I am trying to list all files and folders but with their size in MBs. I tried multiple things, but unable to get what I am trying for. Like in Unix I can hit the following: ls -lrh and get the output
I tried and it gives me this:
(gci "C:\Users\test\OneDrive\Word\Client\" | Measure Length -s).sum / 1MB
17.6003713607788
The final output should be something like this:
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---l 4/9/2021 12:31 AM 1.7 MB Client_Changes.docx
-a---l 7/21/2021 11:08 AM 6 MB Test_Files.docx
-a---l 7/15/2021 12:58 PM 0.6 MB Test_files2.docx
Something like this
dir | ft -Property mode,lastwritetime, @{Name="Size MB";Expression={$_.Length / 1mb}; format = '0.0'},name
- gastoneBrass Contributor
Something like this
dir | ft -Property mode,lastwritetime, @{Name="Size MB";Expression={$_.Length / 1mb}; format = '0.0'},name