get size of items in finder

If I do:

try
tell application “Finder” to set thisList to items of folder xxx
on error
set thisList to {}
end try
repeat with i in thisLisT
log size of i
end repeat

I get “missing value”, if I start this script a second time, I get no “missing values”, but if I restart the mac I get again “missing values”

tell application "Finder" to size of i
log result

Or, if you’re dealing only with files:

log size of (info for (i as alias))

thanks, it works, but it is really slow, to slow for my application

set myPath to “Applications”
set a to “”
try
tell application “Finder” to set backupFolders to items of folder myPath
on error
set backupFolders to {}
end try

repeat with i in backupFolders
set a to a & return & name of i & tab & size of (info for (i as alias))
end repeat
display dialog a as string

Then, you may use the shell, something similar to this:

do shell script "find ~/Documents -type f -ls -maxdepth 1 | awk '{print $11, $12, $13, $7}'"

Take a look to “man find” or “man ls” (or “man wc”) in the Terminal.

thank you, I tried:

set x to name of i & " " & word 1 of (do shell script "du -k -d 0 " & POSIX path of (fromPath & “:” & name of i))

in the repeat loop, but if I selected the applications folder, it takes about 20 sec to take all information.

I want to to a list with name and size of all items of a folder like documents, home, applications, … It should be pretty fast to get all infomartion (name and size) of the folder. I need this to desplaye the items (with size) in my application. With your script I get only files, but no folders.

Yeah, I was getting a similiar problem: sometimes ‘size’ reports missing value for no appearent reason. Note: ‘physical size’ presented no problems.

In any case, this is pretty useful:


set f to choose folder --> for debugging

tell application "Finder" to get {name, size} of every item of entire contents of f

What you get back is a list of 2 lists, the first list contains item names, while the second contains their corrosponding sizes. You can also just get folder info, if that’s what you’re primarily interested in:


set f to choose folder --> for debugging

tell application "Finder" to get {name, size} of every folder of entire contents of f
--
--	{	{ "My Folder 1", "My Folder 2", etc...},
--		{  3.2249654E+7,        8053.0, etc...}
--	}

thank you
I’m interested in name and size of every item (files, folders, app) in a folder to add them in a table view.
I did:
set myPath to (“Users:” & (do shell script “echo $USER”))
tell application “Finder” to get {name, size} of every item of folder myPath
set thisItems to result
set nameI to item 1 of thisItems
set sizeI to item 2 of thisItems
repeat with i from 1 to length of nameI
set a to a & return & item i of nameI & " " & item i of sizeI
end repeat
display dialog a as string

but i get always “missing values”, until I did it again

Yeah, this definately seems like a bug. The problem doesn’t
seem to occur with ‘physical size’, can you use that instead?


tell application "Finder" to get {name, physical size} of every item of folder myPath

I get “missing values” if I use “physical size” or “size”

Wow, this is a serious bug:


tell application "Finder"

	get size of (choose folder)

end tell

I seem to randomly get either ‘missing value’, 0.0, or the
actual value I want, especially with the “special” folders of
the OS, like Applications, Users, etc.

I was going to recommend using the ‘info for’ osax command:


get size of (info for (choose folder))

but this turned out to be extremely slow for large folders like
“Applications”. ‘infor for’ seems to calculate a size rather than
have it readily at hand as the Finder’s ‘size’ property does.

try this, it works (not very fast, but ok), it never shows “missing value” or 0.0!!!

set fromPath to “Users:” & (do shell script “echo $USER” & “:Desktop”)
set a to “”
try
tell application “Finder” to set the sourceFolder to folder fromPath as alias
set the itemList to list folder sourceFolder without invisibles
on error
set itemList to {}
end try
repeat with i from 1 to count of itemList
set currentInfo to info for (((sourceFolder as string) & item i of itemList) as alias)
set the currentName to the name of currentInfo
set currentSize to (size of currentInfo)
set a to a & return & currentName & tab & currentSize
end repeat