Strange size conversion

I must be missing something real important, here is my problem :

using the ‘info for’ command I’m retrieving the size of a file (in bytes) adI 'm trying to convert it to kilobytes or megabytes using the formula :
1 kilobytes = 1024 bytes
1 megabytes = 1024 kilobytes = (1024)^2 bytes

And the result is not whta is shown in the info window. Can someone explain it to me?

Notice : when I’m using the “Finder” physical size for (pathToFile), I have teh correct result, but I’d like not to use the “Finder”.

So there is a difference between the real size of the file, and the place this file is taking on the disk (which is understandable)

Here are a couple of quotes from Chris Nebel, AppleScript engineer. These statements were made at different times in response to different questions, but they might help. Obviously, you’ve already touched on some of the issues mentioned by Chris.

Thanks Rob
Here is a little handler dedicated to finding the size taken by the file on the disk (physical size) without using the Finder


on getFileSize(PathToFile)
	set myOffSet to offset of "/" in (reverse of characters of PathToFile as string)
	set lastcar to ((count PathToFile) - myOffSet) + 1
	set ParentPath to characters 1 thru lastcar of PathToFile as string
	set FileName to characters (lastcar + 1) thru -1 of PathToFile as string
	do shell script "cd " & ParentPath & ";" & "ls -sk | grep " & FileName & " | awk '{print $1}'"
end getFileSize

:cry: but it works only for file that are less that 1 Mo

This shorter snippet should work just as well.

on getFileSize(PathToFile)
   do shell script "ls -skc1 " & PathToFile & " | awk '{print $1}'"
end getFileSize

What do you get if the file size is greater than 1 MB?

Thanks for the tip, it’s working well with your routine

(et voila, second problem solved…)