One liner PowerShell for getting directory size (in GB)

Community for Programmers and Developers. C, C++, C#, Basic, Perl, VB, VBS, Java, Javascript, PHP, CGI, HTML and More!
Forum rules
• If you are posting source code, proper indenting and comments will improve the readability.
User avatar
3ICE
Admin
Posts: 2520
Joined: Sat Mar 01, 2008 11:34 pm
Realm: Europe
Account: 3ICE
Clan: 3ICE
Location: Hungary
Contact:

One liner PowerShell for getting directory size (in GB)

Unread post by 3ICE »

Code: Select all

'{0:0.0} GiB' -f (((Get-ChildItem -Recurse | Measure-Object -Sum Length).Sum) / 1GB)
Shortest form:

Code: Select all

'{0:0.0} GiB' -f (((ls -r | measure -s Length).Sum) / 1GB)
In action:
One liner PowerShell for getting directory size (in GB).png
One liner PowerShell for getting directory size (in GB).png (5.35 KiB) Viewed 2126 times
(Shows 1.7 GB, which is correct.)
ImageImageImageImageImage
Image
ImageImage

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests