Sort by folder size
Hello every one! I have this script:
$log = ".\logfile.log"
$startFolder = "C:\VMs"
$colItems = Get-ChildItem $startFolder | Where-Object {$_.PSIsContainer -eq $True} | Sort-Object
foreach ($i in $colItems){
$itemSum = Get-ChildItem ("$startFolder\" + $i.Name) -recurse | Measure-Object -property length -sum
"$startFolder\$i -- " + "{0:N2}" -f ($itemSum.sum / 1KB) + " KB" >> $log
import-csv $log -delimiter "`t" | export-csv .\TEST.csv
$body = Get-Content $log | Sort | Out-String
Send-MailMessage -From [email protected] -To [email protected] -Subject "Test Theme" -attachment .\TEST.csv -Encoding ([System.Text.Encoding]::UTF8) -Body $body -SmtpServer test123.test.local
Remove-Item $log
Remove-Item .\TEST.csv
When this script done I
receive something like this in email message:
C:\VMs\Backup -- 0,00 KB
C:\VMs\Vbox -- 82 874 750,42 KB
C:\VMs\VMWARE_BACKUP -- 182 818,77 KB
How I can change this script to sort by folder size?
Not alphabetically.
Thanks in advance!
Hello Darkwind,
you can do this, but it'll require some reformatting your script. I've done the honors:
$startFolder = "C:\VMs"
# Get folders
$colItems = Get-ChildItem $startFolder | Where-Object {$_.PSIsContainer -eq $True} | Sort-Object
# This one will do the measuring for us
$fso = New-Object -ComObject Scripting.FileSystemObject
# iterate over each folder and measure length
$FolderReport = @()
foreach ($i in $colItems)
# 1: Get Size
$folder = $fso.GetFolder($i.FullName)
$size = $folder.size
# 2: Set Properties in a hashtable
$props = @{
name = $i.FullName
size = $size
displaysize = (("{0:N2}" -f ($size / 1KB)) + " KB")
# 3: Add to results
$FolderReport += New-Object PSObject -Property $props
# Sort results
$FolderReport = $FolderReport | Sort size
# Build CSV attachment
$FolderReport | export-csv .\TEST.csv
# Build body
$lines = @()
$FolderReport | %{$lines += ($_.name + " -- " + $_.displaysize)}
$body = $lines -join "`n"
# Send mail
Send-MailMessage -From [email protected] -To [email protected] -Subject "Test Theme" -attachment .\TEST.csv -Encoding ([System.Text.Encoding]::UTF8) -Body $body -SmtpServer test123.test.local
# Cleanup file
Remove-Item .\TEST.csv
As you can see, some slight modifications :)
Now, just what did I change ...
I used the Scripting.FileSystemObject Comobject to measure size, since that's a bit faster.
When selecting the size, I built custom objects containing the information (Name & size), since if we want to sort by size, we need to keep it as a separate property.
Then I sorted by size, and exported the result into a csv file for attachment
I built the body from strings in memory - no point writing it to a file, just to reread it. (that "`n" should work as a linebreak)
Cheers,
Fred
There's no place like 127.0.0.1
Thank You! It's work for me!
But this script first shows the
folders from the small to the larger
size. Is it possible to do the opposite?
Similar Messages
-
Why does Time Machine folder sizes exceed physical capacity?
I have a MAC G3 Server Serving multiple MACs as a Storage, Media Server, and Time Machine storage. These other external MACs are all running Version 10.8.3. Only the Storage server is running 10.5.8.
All of the extenal Macs use Time Machine to backup to the served Storage media volume called "Time Machine".
The physical size of the "Time Machine" volume is 2.0 TB.
Yet when I am on the G3 Server, and perform a "Get Info" on the "Time Machine" volume, and also the folder that contains the Server's backups, the stored capacities exceed the physical capacity of the drive to which the volume resides.
The single physical drive is 2.0 GB and only has one partition called "Time Machine". In the root directory of this volume there is the one folder called Backups.backupdb, and a .sparsebundle DMG file for each of the remote systems that are bing backed up by Time Machine.
Each of the sparsebundles are well below the dirve's physical capacity, but both the local server's backup folder (Backups.backupdb) and the G3 server's local volume "Time Machine" show a used capcity that well exceeds the physical capacity of the drive on which it resides.
For example, here is the information from "Get Info" on the Backups.backupdb folder on the "Time Machine" volume when viewed from all systems:
Kind: Folder
Size: 3,456,930,478,415 bytes (3.46 TB on disk) for 122,254 items
But the Physical Volume "Get Info" shows this:
Kind: Volume
Capacity: 2.0 TB
Available: 169.92 GB
Used: 3,456,930,478,415 bytes (3.46 TB on disk) for 122,254 items
(NOTE: this is identical to the size
My guess is that there is some sort of deduplication involved.
If so, I would like to know the type of deduplication is performed?
Is it File Level deduplication, Block Level, or Content Level?
Also, is the deduplication inhererant on the volume (File System) level, or only specifically for Time Machine, via symbolic links?
Thank you in advance.
Jeff CameronThis is due to the way Time Machine stores files. While there is only one copy of each version of each file stored, there are multple links to that file, and each link is reported in Get Info at its restored size.
How Time Machine Works its Magic -
How to get folder size in bytes
Hi all,
Is there a easy way to get folder size in bytes? I don't want to check each file in it and then add them up.
Thanks for any help.
AnneYears ago, I found my home PC was lacking disk space and could not exaplain where all of the space went.
At the same time I was teaching myslef how to use the Picture control and Windows did not allow you to check the size of a folder and it sub-folders. So I used that situation to learn about the picture control and LV at the same time.
It worked and ran but very slowly.
Soon after Greg McKaskle was putting together the first version of "The Good The Bad and The Ugly" and was looking for fodder to beat up. I offered and he accepted. When the time came for the presentation, my code was chosen as "The bad" since I had not learned how to do a cluster sort at that time so I wrote my own version of a bubble sort (the VI presents a Pie Chart of disk usage and clcik on the sectors of the Pie Chart allowed you to drill down so I hd to sort by sizes).
So why am I telling you this long boring story?
That code is attached for you to look at laugh and tell me how dumb I was.
Feel free to beat me up. It can't be any worse than the abuse I got from Greg (I felt like I was being raped).
Have fun!
Ben
Code is probably 6 or thereabouts. "Disk_Utility" is top level. Remember this is an example of how NOT to code.
Ben Rayner
I am currently active on.. MainStream Preppers
Rayner's Ridge is under construction
Attachments:
DIsk_Pie_Utility.zip 162 KB -
How can I set the preferences to calculate the size of folders on the hard drive?
Hi Dave,
You can see the folder sizes in List View.
While in List View, under the View Menu, select "Show View Options",
then check the boxes for "Size" and "Calculate all sizes"
Note while in List view, you can then sort by size by clicking on the Size column header. You can also reverse the sort by clicking it again. This works with any column header.
Ivan -
Get folder size error 800A004C
I am trying to make a script Counts the size of a folder.
I am getting a vbs error "Path not found" 800A004C on line 19 (Q = Q + F.size)
dim oFS, oFolder
set oFS = WScript.CreateObject("Scripting.FileSystemObject")
set oFolder = oFS.GetFolder("E:\NEW-backup\")
set qFS = WScript.CreateObject("Scripting.FileSystemObject")
set logFolder = qFS.GetFolder("E:\Backup Logs\")
ShowFolderDetails oFolder
sub ShowFolderDetails(oF)
dim F
dim Q
dim antalGB
dim attachment
dim subject
Q=0
for each F in oF.Subfolders
Q = Q + F.Size
Next
antalGB = "Dagens backup fylder: " + FormatNumber(((Q/1024)/1024)/1024, 2) + " GB" + "\n\nMvh\n"
If I run the script on E:\Backup instead of E:\NEW-backup I get no errors.
Please help I am a noob to scriptingIf you can try in PowerShell - the below sample code may help you - THis returns folder size in MB
function Get-FolderSize
param ( [String]$Path )
$FileSystemObject = New-Object -com Scripting.FileSystemObject
$folders = (Get-Childitem $path | ? {$_.Attributes -eq "Directory"})
foreach ($folder in $folders)
$folder | Add-Member -MemberType NoteProperty -Name "SizeMB" –Value(($FileSystemObject.GetFolder($folder.FullName).Size) / 1MB)
$folders | sort -Property SizeMB -Descending | select fullname,@{n=’Size MB’;e={"{0:N2}" –f $_.SizeMB}}
Get-FolderSize -Path C:\Temp\
You may get some insight / help for your code as well!
Regards Chen V [MCTS SharePoint 2010] -
Hi,
I am moving from Outlook to apple mail. one of my outlook mail folders hat around 4GB. Whats the max folder size in Apple Mail?
Thank youi for your answer,
best regards
RobertOk, I've been working a little on the problem at hand.
If I use the "Rebuild" command on the mailbox, I get duplicates of all message.
I decided then to use the script found on www.homepage.mac.com/aamann/ (great tool btw) to remove duplicate message. The script take a little time for the 800 so messages but finds all the duplicates and moves them to a "duplicate" mailbox from where you can trash them. Trash, empty trash in Mail, quit Mail, relauch Mail...
The mbox folder now contains the right number of message, but the size is still bigger than expected. Digging in, the mbox folder contains two folder (Message + Attachments) as opposed to only one (Message) in Leopard. By observation, it is clear that the attachments (found embedded in the message file in the Message folder) can also be found in the the Attachments folder... therefore the reason for the apparent doubling size of the "Mail" folder!
Ok, now there is some sort of solution (rebuild, duplicate removal) but that doesn't sort out the fact that attachments are found in two places, thus eating up twice the disk space.
Still need help!
Bisondesprairies -
I read on some site that there is an app that allows one to increase the desktop folder size limit in iOS 5.0.1 on an iPad2 does anyone have any info please?
Thanks for any thoughts in advance.....
DaveFirstly, Thanks for taking the time to reply :-)
It's not that I want gazillions of apps, I just wanted to put more in each folder so I don't have to have multiple folders with similar names....Weather1, 2, 3,etc.... but I see your point and appreciate the thoughts.
Dave -
Outlook 2010 - Data File Properties/Folder Size verses Windows Explorer pst file size
I am running Outlook 2010 32bit Version 14.0.6129.5000 on a Windows PC running Windows 7 Professional. All updates from MS are up to date.
I have several pst files I open with Outlook 2010. The size of the files displayed in Outlook are very different than what is displayed in Windows Explorer.
For example one of the pst file called "business.pst" when opened Outlook displays it under "Data File Properties -> Folder Size" that the Total Size (including subfolders) is 764,354 KB. Windows Explorer says
the file size is 1,190,417 KB.
For some reason MS Outlook 2010 is displaying the wrong folder size. Any ideas why this is the case?
Thanks,
PatOutlook mailbox grows as you create and receive items. When you delete items, the size of the Outlook Data File (.pst and .ost) file might not decrease in proportion to the data that you deleted, untill it has been compacted.
Normally, after you have deleted items from an Outlook Data File (.pst), the file will be automatically compacted in the background when you’re not using your computer and Outlook is running.
For an exception, when the Outlook Data File (.pst) is somehow corrupt, the compaction might not finish correctly. So the size of the Outlook Data File (.pst) file might remain the same before compaction.
To solve this, try run the
scanpst to fix the Outlook Data File (.pst) file first, after that, we can
manually start the compact command.
When finished, compare the file size again.
Max Meng
TechNet Community Support -
Finder won't display folder size in "Size" column or Info window
Normally, the Finder window will display a folder's size in the Size column. However, I have one folder which shows as "Zero KB" in the Size column. When I open the General Info window, the Size reads as "Zero KB on disk (Zero bytes) for 0 items."
In order to get the folder size I have to go into the folder, select all folders (there's many), then with either the Summary Info or Inspector window, it'll show the folder size ("185.32 GB on disk").
Why is this occurring in only this folder? Is it because it's a large folder or a folder with many subfolders?
I'm running Snow Lep 10.6.2. The folder is on an external drive in FAT32 format. I've already tried deleting the "com.apple.finder.plist" file and rebooting.
Thanks for any help.go to view menu->show view options and check the box 'calculate all sizes". then click "use as defaults".
-
Finder Folder Size Calculations
When I'm archiving, I have to do a lot of Get Info to calculate the folder sizes for DVD burning. Problem I'm having is the file size calculations start taking forever after working for a few minutes, or they don't calculate at all. Usually works fine when I start but after a minute or so It's like the computer get's tired and just stops. Even if it's a 1mb folder it will have trouble.
Is this normal? Seems really odd that something so incredibly simple can make my archiving process so difficult.
Files reside on a network HD.
Thanks for any help.I'd create a disk image of appropriate size, mount it, copy items to it until it tells you there's no more room. Then, burn it.
-
File / Folder size... How do Finder gets it?
Hi there!
While checking some of my hardrives for sucessfull shell script execution backups, i noticed that Finder took a loooot of time to provide the info about the Folder / File size on the Information window, while a simple ls -l could provide on the fly values regarding file or folder size, as always, fast simple and faithfull unix mindset!
Well, that makes me wonder, how does Finder calculates those values? Anyone got an hint?
Does it make it all by himself, if so. WHY? Been an "posix" system, shouldn't he be using whats already provided by its *nix heritage?
In this case, the value is already there, why don't use it and simply parse it to the desired format (MB / GB / TB)?
Maybe this could be only one of several features (GUI) that could improve it's performance from being more "conscious" of the system natively provided "toolkit".
Please, this is only my humble thouhgts on this, and please do shut me up if totally wrong!
Hope to get some nice and interesting feedback from the OS X community!
If there's a better spot to start this kind of discussion, please do mention it, i will appreciate it!
Best regards.Properties. Short Cuts, Change Icon resolved the issue after restarting. Problem resolved.. Thank you for all the help Dwain
-
Share Point folder size limit - File Services
I created a new folder inside a share point using Server Admin. Is there a way to set a folder size limit (quota) for that folder.
P.S. I am NOT talking about user accounts quotas for home folders created using Workgroup Manager! ...Just any new folder created, to be used on any volume, is there a way to set a mamimum size?
For example I have a 1TB volume on my Xserve RAID. I create a new folder but want to set its maximum capacity to 200GB. Is that possible?
Thank you very much in advance for any feedback.There's no direct way to set a limit on a folder size.
The 'simplest' method I can think of is to create partitions on your disk of the appropriate sizes and share these - they will have inherent size limits based on the size of the partition. It's a little messier but should solve your issue.
:: thinking :: you might be able to use disk images rather than partitions, although I've never tried sharing a mounted disk image, and you'd need to address automounting the disk images when the server starts, so it might not be viable. -
Maximum folder size in 10.5.2?
What is the maximum folder size now in 10.5.2?
For around 10 years I've been using numerous partitions to organize my files and for easy backup, but I know that quite a while ago (years) the maximum folder size was dramatically increased (2GB > ?).
Has anyone had problems with these larger folders?
My files are extremely important (clients' files) so safety and stability are more important to me than anything else (i.e. the simplicity of fewer partitions perhaps).
Of course I could simply do a search for specs regarding this on Apple's website, but it would not indicate as to just how stable such huge folders have been for everyone.
Thanks for any info on this.I went to
http://en.wikipedia.org/wiki/HierarchicalFileSystem
And I did carefully read the Apple white paper but still no where do I see a maximum folder size for within a volume
So I can only assume there is no maximum... that is... that you can actually have literally all of your files and folders in a volume within one folder even if it takes up 90% of the volume's/partition's space.
I originally posted this because rather than reformatting a couple of my hard drives... I was considering moving a couple of the partitions contents (each with around 40 GB of important files) to a larger partition and place each partition's contents in to individual folders. In-other-words... moving two 40 GB partitions to two separate folders within another 100 GB + partition. Thereby freeing up two 40 GB partitions without having to reformat my drives.
Anyone see a problem with that? -
Sort by file size and/or pixel dimensions
I am constantly frustrated by the lack of ability to sort by file size or pixel dimension. I have many versions of the same images, and often want to find the biggest one, or one of a certain size, and it's very time consuming to have to scan all the numbers in the metadata instead of being able to sort. Please add this.
Thanks!DevMeta will allow you to filter/collect by width and height dimensions.
PixelCountMetadata will allow you to filter/collect by total number of pixels (width x height).
Now that I'm thinking about it, I should probably have just added the pixelcount metadata to DevMeta, but I didnt..., yet...
PS - I dont use PixelCountMetadata, since I only have originals in Lightroom. All resized copies are kept outside of Lightroom. Consider TreeSync if you regularly keep variously sized copies at the ready for various purposes... And, lastly, ExportManager will help you keep all your trees up2date, if you have more than one.
I then use ACDSee to find photos in the exported copies or run slideshows, or serve on the house net, or email...
R -
Folder size is twice that of its contents????
Startup Disk > Users > Username
My Username folder shows a folder size that is just about double the size of all of its visible folders. I can see this when viewed in the Finder in List View with Folder Size Shown as my default View setting. Any idea how I can figure out what is going on?
thanks
BradTopher,
Before I saw your reply, I emptied my trash and that brought the folder size down to what it should be to match its contents. I should have remembered that. None the less, I did what you suggested once I read your message and here it is:
total 2240
drwxr-xrwx 34 brad 503 1156 Feb 27 16:13 .
drwxr-xr-x 7 root admin 238 Dec 1 08:00 ..
-r-------- 1 brad 503 7 Dec 1 07:48 .CFUserTextEncoding
-rw-r--r--@ 1 brad 503 12292 Mar 1 16:22 .DS_Store
drwx------ 5 brad 503 170 Mar 1 16:42 .Trash
drwxr-x--x 4 brad 503 136 Apr 19 2011 .adobe
drwxr-xr-x@ 3 brad 503 102 Apr 27 2011 .autodesk
-rw------- 1 brad 503 546 Feb 15 2012 .bash_history
drwxr-xr-x 6 brad 503 204 Aug 28 2014 .blurb
drwx------ 3 brad 503 102 Feb 27 2014 .cache
drwxr-xr-x 4 brad 503 136 Feb 27 2014 .config
drwx------ 3 brad 503 102 Dec 6 2010 .cups
-rw-r--r-- 1 brad 503 1109647 Sep 23 2011 .fonts.cache-1
drwxr-xr-x 2 brad 503 68 Jun 18 2013 .gs5
drwxr-xr-x 3 brad 503 102 Sep 6 2011 .local
-rw-r--r-- 1 brad 503 239 Sep 6 2011 .mailcap
-rw-r--r-- 1 brad 503 368 Sep 6 2011 .mime.types
drwxr-xr-x 3 brad 503 102 Dec 18 2012 .viewcd
-rw-r--r-- 1 brad 503 90 Apr 17 2013 .vuescanrc
drwxr-xr-x 8 brad 503 272 Jun 26 2014 .wapi
drwxr-xr-x 4 brad 503 136 Dec 4 12:23 Applications
drwx------@ 3 brad 503 102 Dec 20 11:44 Creative Cloud Files
drwx---rwx@ 40 brad 503 1360 Mar 1 16:48 Desktop
drwx---rwx+ 7 brad 503 238 Nov 12 18:30 Documents
drwx------+ 3 brad 503 102 Feb 20 16:42 Downloads
drwx------@ 4 brad 503 136 Feb 22 22:43 Google Drive
drwxrwxr-x 5 brad admin 170 Dec 7 18:07 Incompatible Software
drwx------+ 66 brad 503 2244 Mar 1 15:07 Library
drwx------+ 5 brad 503 170 Sep 21 19:42 Movies
Maybe you are looking for
-
WordWrsp not Working in JDK1.5?
Hello All I am using JDK 1.5_03 I have a editor kind of stuff for which I have used setLineWrap(true);for JTextAreaHowever this is not working. This is working in 1.4.2_X versions. Has any one encountered this problem?
-
Problem with ePub Table of Contents
In converting to ePub format, I end up with the TOC out of sync. For instance chapter 1 in the TOC actually points to chapter 2, chapter 2 to 3, etc. When I make a PDF from the same file, everything is OK. Even in the Pages document the links work as
-
Which are the advantages of OWB Mappings over PLSQL code?
Hi, I was wondering which are the advantages of OWB (10gr2 or 11g) Mappings vs simple PLSQL code when the mappings are, for performance reasons, only generated in set based mode. Regards Maurice
-
Unable to sync iphone4. iphone not recognized. wants me to restore factory settings. I've done that several times and problem persists.This has been an issue sunce buying the phone.
-
ITunes stops working after launch.
I have iTunes installed on a PC running Windows 7. I have just installed the latest iTunes update. Now within 15 seconds of starting iTunes I receive an error message: "iTunes has stopped working" and the program closes. I have tried rebooting the PC