![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Get size of folders and subfolders that meet a certain criteria Im looking to use powershell to run through a directory tree and tell me the size of all folders that are called desktop, but also the subfolders of the desktop folder. Any ideas. Thanks Claire |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Get size of folders and subfolders that meet a certain criteria On Aug 17, 11:12 am, claire <clairesruss...@gmail.com> wrote: > Im looking to use powershell to run through a directory tree and tell > me the size of all folders that are called desktop, but also the > subfolders of the desktop folder. > > Any ideas. > > Thanks > Claire starting at c:\documents and settings ps > dir -rec -include desktop | % { $_.pspath; dir $_ -rec | ? {! $_.psiscontainer } | measure-object -sum length | % { "{0:0.00}MB" -f ($_.sum / 1mb) } } (split onto two lines for brevity) sequence, split by pipe segments: 1) get all child items matching "desktop" and pass to next segment 2) for each item received, output its path; then get all child items and pass to next segment 3) if item is not a container (e.g. file) then pass to next segment. 4) sum all the "length" properties of each object received, and pass results to next segment 5) for each result, format to two decimal places, in megabytes. Hope this helps, - Oisin |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Get size of folders and subfolders that meet a certain criteria On Aug 17, 11:12 am, claire <clairesruss...@gmail.com> wrote: > Im looking to use powershell to run through a directory tree and tell > me the size of all folders that are called desktop, but also the > subfolders of the desktop folder. > > Any ideas. > > Thanks > Claire and for the second part of your question: dir -rec -include desktop | % { $_.pspath; dir $_ -rec | ? {$_.psiscontainer} | % { $_.pspath } } you should be able to understand this from the first explanation. Hope this helps, - Oisin |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Get size of folders and subfolders that meet a certain criteria Try this: function folderSize ([string]$path, [switch]$recurse) { $totalSize = 0 Get-ChildItem $path -recurse:$recurse -force | where {-not $_.psIsContainer} | % {$totalSize += $_.length} $totalSize } $path = "C:\Documents and Settings" $desktopRoots = @(get-childItem $path -filter desktop -recurse -force | where {$_.psIsContainer} | % {$_.fullName}) $desktopSubFolders = @($rootDesktop | % {get-childItem $_ -recurse -force | where {$_.psIsContainer} | % {$_.fullName}}) $rootDesktop | foreach {"{0,8:n1} MB $_" -f $((folderSize $_ -r) / 1mb); $x = $_; $desktopSubfolders -match [regex]::escape($_) | % {"{0,8:n1} MB $($_ -replace [regex]::escape($x))" -f $((folderSize $_) / 1mb)}} -- Kiron |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Get size of folders and subfolders that meet a certain criteria I came up with this one. get-childitem c:\users -include Desktop -recurse | %{$name = $_.fullname;get-childitem $_.fullname -recurse | Measure-Object -Sum Length | %{"{1} is {0:n2}MB" -f ($_.Sum/1mb),($name)}} Or in pretty form $desktops = get-childitem c:\pathtofolder -include Desktop -recurse foreach($desktop in $desktops) { $name = $desktop.fullname get-childitem $name -recurse | Measure-Object -Sum Length | %{"{1} is {0:n2}MB" -f ($_.Sum/1mb),($name)} } "claire" <clairesrussell@gmail.com> wrote in message news:1187363528.500635.115360@50g2000hsm.googlegroups.com... > Im looking to use powershell to run through a directory tree and tell > me the size of all folders that are called desktop, but also the > subfolders of the desktop folder. > > Any ideas. > > Thanks > Claire > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Get size of folders and subfolders that meet a certain criteria Sorry, there was a typo in the previous post. ![]() function folderSize ([string]$path, [switch]$recurse) { $totalSize = 0 Get-ChildItem $path -recurse:$recurse -force | where {-not $_.psIsContainer} | % {$totalSize += $_.length} $totalSize } $path = "C:\Documents and Settings" $desktopRoots = @(get-childItem $path -filter desktop -recurse -force | where {$_.psIsContainer} | % {$_.fullName}) $desktopSubFolders = @($desktopRoots | % {get-childItem $_ -recurse -force | where {$_.psIsContainer} | % {$_.fullName}}) $desktopRoots | foreach {"{0,8:n1} MB $_" -f $((folderSize $_ -r) / 1mb); $x = $_; $desktopSubfolders -match [regex]::escape($_) | % {"{0,8:n1} MB $($_ -replace [regex]::escape($x))" -f $((folderSize $_) / 1mb)} } -- Kiron |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Get size of folders and subfolders that meet a certain criteria On 17 Aug, 16:25, Oisin Grehan <ois...@gmail.com> wrote: > On Aug 17, 11:12 am, claire <clairesruss...@gmail.com> wrote: > > > Im looking to usepowershellto run through adirectorytree and tell > > me thesizeof all folders that are called desktop, but also the > > subfolders of the desktop folder. > > > Any ideas. > > > Thanks > > Claire > > starting at c:\documents and settings > > ps > dir -rec -include desktop | % { $_.pspath; dir $_ -rec | ? {! > $_.psiscontainer } | > measure-object -sum length | % { "{0:0.00}MB" -f ($_.sum / > 1mb) } } > > (split onto two lines for brevity) > > sequence, split by pipe segments: > > 1)getall child items matching "desktop" and pass to next segment > > 2) for each item received, output its path; thengetall child items > and pass to next segment > > 3) if item is not a container (e.g. file) then pass to next segment. > > 4) sum all the "length" properties of each object received, and pass > results to next segment > > 5) for each result, format to two decimal places, in megabytes. > > Hope this helps, > > - Oisin Thanks for your help on this one its exactly what I want, just one more quick question if i wanted to output it to a csv file but have the size on the same line as the path what would i need to do. When I tried to add the export-csv to the the pipeline i just get the sizes not the paths. Thanks again |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Get size of folders and subfolders that meet a certain criteria On 17 Aug, 21:51, "Brandon Shell" <tshell.m...@mk.gmail.com> wrote: > I came up with this one. > get-childitem c:\users -include Desktop -recurse | %{$name = > $_.fullname;get-childitem $_.fullname -recurse | Measure-Object -Sum Length > | %{"{1} is {0:n2}MB" -f ($_.Sum/1mb),($name)}} > > Or in pretty form > $desktops = get-childitem c:\pathtofolder -include Desktop -recurse > foreach($desktop in $desktops) > { > $name = $desktop.fullname > get-childitem $name -recurse | Measure-Object -Sum Length | %{"{1} is > {0:n2}MB" -f ($_.Sum/1mb),($name)} > > } > "claire" <clairesruss...@gmail.com> wrote in message > > news:1187363528.500635.115360@50g2000hsm.googlegroups.com... > > > > > Im looking to use powershell to run through a directory tree and tell > > me the size of all folders that are called desktop, but also the > > subfolders of the desktop folder. > > > Any ideas. > > > Thanks > > Claire- Hide quoted text - > > - Show quoted text - Brandon thanks for that, I'm now trying to this to output to a file but I need the path and total to appear on the same line, I have used out-file -append but that still puts a line feed in. Any ideas on how to achieve this. Thanks again for your help Claire |
My System Specs![]() |
| | #9 (permalink) |
| | Re: Get size of folders and subfolders that meet a certain criteria $path = "C:\Documents and Settings" get-childItem $path Desktop -recurse | where {$_.psIsContainer} | select @{name = 'Path'; expression = {$_.fullname}}, @{name = 'Size'; expression = {"{0:n2}MB" -f ((gci $_.fullname -recurse | measure-object -sum length).sum/1mb)}} | export-csv Desktops.csv -NoType get-content Desktops.csv --------- In this case you can use calculated property/field '@{name = <string>; expression = {<scriptblock>}}' For an explanation on calculated property/field: (get-help select-object).description ((get-help select-object).examples).example[3] -- Kiron |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Local folders: names of subfolders | Vista mail | |||
| How do I unlock Documents folders and subfolders? | Vista file management | |||
| deleting files that meet specific criteria | PowerShell | |||
| batch renaming folders including subfolders | Vista General | |||
| RC1 install problem: Disk does not meet the criteria to install vi | Vista installation & setup | |||