Reputation: 13
I have created a directory list of files like this:
JPGS.LST:
"L:\_Testing\2016-05-20 20.22.53.jpg"
"L:\_Testing\2016-05-20 20.23.07.jpg"
"L:\_Testing\2016-05-20 20.23.12.jpg"
"L:\_Testing\2016-05-20 20.59.31.jpg"
"L:\_Testing\2016-05-20 21.19.25.jpg"
"L:\_Testing\2016-05-20 21.19.28.jpg"
"L:\_Testing\2016-05-20 21.49.09.jpg"
"L:\_Testing\2016-05-20 21.49.12.jpg"
From this list I want to get a total of all the file sizes - from the list.
I'm using this list to reduce these images. I want to run the script again to see total size of the same files after the reduction, so I have a before and after comparison. Other examples I see use a powershell directory listing...I need to be able to use the input file to determine total size of files in the directory listing.
I've tried:
$Files=Get-Content $Listfile
$totalSize = ($Files | Measure-Object -Property Length -Sum Length).Sum
but that's not producing expected results. I'd like it to resolve to something like
$TotalSize=12.5 MB
Obi Wan....you're my only hope!
Upvotes: 0
Views: 2158
Reputation:
You will have to iterate the files contained in JPGS.LST:
$TotalSize = 0
ForEach ($File in Get-Content '.\JPGS.LST'){
If (Test-Path $File.Trim('"')){$TotalSize+=(GI $File.Trim('"')).Length}else{"$File not found"}
}
"`$TotalSize={0:N2} MB" -f ($TotalSize/1MB)
Upvotes: 1
Reputation: 1782
Perhaps this is what you want:
ls -recurse | % { [long]($_.Length) } | Measure-Object -sum | % { $_.Sum }
Upvotes: 1
Reputation: 506
$files = Get-ChildItem $path -Recurse -File
$sum=($files | Measure-Object -Property length -Sum).sum
If you want a desired output with sum (MB, GB ..etc), check PowerShell display files size as KB, MB, or GB discussion with cool techniques.
Upvotes: 2