![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Directory Size using PowerShell Hello, I have about 45 directories that have about 10 nested directories with tens of thousands of files in the directory. I have folder compression turned on since most of my files are .txt and I get a 2:1 compression. I would like a Powershell script that can recurively scan a root directory of my choosing and simply give me the total size of each directory in the root directory, sorted from largest to smallest. Can anyone help me with this? |
My System Specs![]() |
| | #2 (permalink) | ||||||||||||
| Guest | Re: Directory Size using PowerShell Try this: get-childitem | where {$_.PSIsContainer} | foreach { $size = (Get-ChildItem $_ -recurse | where {!$_.PSIsContainer} | Measure-Object -Sum Length).Sum $obj = new-object psobject add-member -inp $obj noteproperty path $_.fullName add-member -inp $obj noteproperty size $size $obj } ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) | ||||||||||||
| Guest | Re: Directory Size using PowerShell dm3281 pisze:
[uint64]$size=0 Get-ChildItem -Recurse | % {$size=$size+$_.Length} $size | ||||||||||||
My System Specs![]() | |||||||||||||
| | #4 (permalink) | ||||||||||||
| Guest | Re: Directory Size using PowerShell Also like this... (gci C:\Folder -recurse | measure-object Length -sum).Sum dm3281 wrote:
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #5 (permalink) | ||||||||||||
| Guest | Re: Directory Size using PowerShell "dm3281" <dm3281@xxxxxx> wrote in message news:5A22D438-3110-4295-BFD5-68EEAF6CE32A@xxxxxx
the typical PowerShell solution then go grab DU.exe from the Sysinternals site: http://technet.microsoft.com/en-us/s.../bb896651.aspx Remember folks to use the right tool for the job. The Filesystem provider performance in v1.0 isn't great and it really shows on issues like this (especially for large dir structures). -- Keith | ||||||||||||
My System Specs![]() | |||||||||||||
| | #6 (permalink) |
| Member ![]() Rep Power: 10 ![]() ![]() ![]() ![]() | Re: Directory Size using PowerShell I was looking for a way to find my 5 biggest folders on my pc. I've downloaded du utility and ran this command du -v | sort -desc | select -first 5 This command gives me this result Totals: ..... Size: ..... Size on disk: .... Files: .... Directory .... So if I want to see these 5 folders I've to write du -v | sort -desc | select -first 10 Is there a way to skip the five lines I wrote above? (like select between 6 and 10) Moreover I have 2 partitions on my hard disk and I'd like to know if it's possible to scan them together to find the 5 biggest folders independently of the unit or if I have to run the command twice and then compares the results. Thanks in advance. |
My System Specs![]() |
| | #7 (permalink) |
| Guest | Re: Directory Size using PowerShell You can do array slicing: (du -v | sort -desc)[6..10] - or - $du = du -v | sort -desc $du[6..$du.length] --- Shay Levy Windows PowerShell MVP http://blogs.microsoft.co.il/blogs/ScriptFanatic s> I was looking for a way to find my 5 biggest folders on my pc. I've s> downloaded du utility and ran this command s> s> du -v | sort -desc | select -first 5 s> s> This command gives me this result s> Totals: ..... s> Size: ..... s> Size on disk: .... s> Files: .... s> Directory .... s> So if I want to see these 5 folders I've to write s> s> du -v | sort -desc | select -first 10 s> s> Is there a way to skip the five lines I wrote above? (like select s> between 6 and 10) s> s> Moreover I have 2 partitions on my hard disk and I'd like to know if s> it's possible to scan them together to find the 5 biggest folders s> independently of the unit or if I have to run the command twice and s> then s> compares the results. s> Thanks in advance. ![]() |
My System Specs![]() |
| | #8 (permalink) |
| Guest | Re: Directory Size using PowerShell Hi sardinian_guy, You can do array slicing using array ranges: (du -v | sort -desc)[6..10] - or - $du = du -v | sort -desc $du[6..$du.length] --- Shay Levy Windows PowerShell MVP http://blogs.microsoft.co.il/blogs/ScriptFanatic s> I was looking for a way to find my 5 biggest folders on my pc. I've s> downloaded du utility and ran this command s> s> du -v | sort -desc | select -first 5 s> s> This command gives me this result s> Totals: ..... s> Size: ..... s> Size on disk: .... s> Files: .... s> Directory .... s> So if I want to see these 5 folders I've to write s> s> du -v | sort -desc | select -first 10 s> s> Is there a way to skip the five lines I wrote above? (like select s> between 6 and 10) s> s> Moreover I have 2 partitions on my hard disk and I'd like to know if s> it's possible to scan them together to find the 5 biggest folders s> independently of the unit or if I have to run the command twice and s> then s> compares the results. s> Thanks in advance. ![]() |
My System Specs![]() |
| | #9 (permalink) |
| Member ![]() Rep Power: 10 ![]() ![]() ![]() ![]() | Re: Directory Size using PowerShell Thank you very much Shay. (du -v | sort -desc)[6..10] it's perfect. I didnt' know this trick. ![]() I have a last question. With du I suppose that it's not possibile to use comparison operators, for instance to find all the folders that are greater than a specified size. I hope I'm wrong. |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| View the size of a directory | Lilllis | Vista General | 7 | 07-29-2008 12:46 PM |
| Powershell & Active Directory | orphan | PowerShell | 3 | 05-03-2007 04:33 AM |
| Recursive directory size in O(1) | yoni | Vista file management | 0 | 10-14-2006 11:10 AM |
| Recursive directory size in O(1) | yoni | Vista file management | 0 | 10-14-2006 11:09 AM |
| Windows directory size? | =?Utf-8?B?Um9i?= | Vista installation & setup | 4 | 09-24-2006 10:48 AM |