Link to home
Start Free TrialLog in
Avatar of wasabi3689
wasabi3689Flag for United States of America

asked on

file size

I want to get the  file size for ".tif" file type in a directory including its sub-directories.

I want to get all the files whose size larger than 20MB each and all the files whose each between 10MB and 20MB
Avatar of oBdA
oBdA

This returns a bunch of objects with a category 0 (less than 10MB), 1 (less than 20MB), 2 (20MB and bigger):
Get-ChildItem C:\Temp -Filter *.tif -Recurse | Select-Object -Property `
	@{n='Category'; e={If ($_.Length -lt 10MB) {0} Else {If ($_.Length -lt 20MB) {1} Else {2}}}},
	@{n='Size MB'; e={[math]::Round($_.Length / 1MB, 2)}}, 
	FullName | Sort-Object -Property Category

Open in new window

Avatar of wasabi3689

ASKER

Can you put an output result to a file? For example, 10-20MB size, this files and its directories, above 20Mb size the files and its directoires
So one file per size category?
Get-ChildItem C:\Temp -Filter *.tif -File -Recurse | 
	Select-Object -Property `
		@{n='Category'; e={If ($_.Length -lt 10MB) {0} Else {If ($_.Length -lt 20MB) {1} Else {2}}}},
		@{n='Size MB'; e={[math]::Round($_.Length / 1MB, 2)}}, 
		Name,
		DirectoryName |
	Group-Object -Property Category |
	ForEach-Object {$_.Group | Export-Csv -NoTypeInformation -Path "C:\Temp\TifSize_$($_.Name).csv"}

Open in new window

I have this error in red

PS D:\NGProductionDocs\Config\Maintenance> .\FindFilePSbySize.PS1
Get-ChildItem : A parameter cannot be found that matches parameter name 'File'.
At D:\NGProductionDocs\Config\Maintenance\FindFilePSbySize.PS1:1 char:79
+ Get-ChildItem F:\NGProductionDocs\NGSourceDocs\ICSStorage  -Filter *.tif -File <<<<  -Recurse |
    + CategoryInfo          : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand




here is the script

Get-ChildItem F:\NGProductionDocs\NGSourceDocs\ICSStorage  -Filter *.tif -File -Recurse | 
	Select-Object -Property `
		@{n='Category'; e={If ($_.Length -lt 20MB) {0} Else {If ($_.Length -lt 30MB) {1} Else {2}}}},
		@{n='Size MB'; e={[math]::Round($_.Length / 1MB, 2)}}, 
		Name,
		DirectoryName |
	Group-Object -Property Category |
	ForEach-Object {$_.Group | Export-Csv -NoTypeInformation -Path "D:\NGProductionDocs\Config\Log\Misc\TifSize_$($_.Name).csv"}

Open in new window

With your filter, you can actually just remove the "-File" argument; I had that in for testing.
And you should seriously consider upgrading to at least PS 3.0. PS 2.0 dates back to 2006.
Hi,

I have an output file something like this


"Category","Size MB","Name","DirectoryName"
"0","0.04","07834A47-82BF-4186-A7D6-1BB8B1E62E5E.tif","F:\NGProductionDocs\NGSourceDocs\ICSStorage\2014\20140101"


"0.04" means 0.04MB, correct?
Yes.
You have files names TifSize_0, TifSize_1, TifSize_02

what are they represented? why TifSize_0 has biggest size?
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial