calculate file sizes

Hi everybody!

today i need a shell script to calculate file sizes. The “Finder” is too slow, especially for big data sizes, like GB.
i construct a routine, but seems not efficient enough, for the reason some files arn’t well calculated. (echo: comment of files)

set data_sz to get size of the_t_ff
				repeat until data_sz ≠ missing value
					delay 1
					set data_sz to round ((size of the_t_ff) / 1024 / 1024)
					if data_sz is 0 then
						set data_sz to 0
					end if
					--display dialog (data_sz as text)
					my procedere(data_sz, the_t_ff, this_f)
				end repeat

du is the command you want:

set tSize to first word of (do shell script "du -d 0 " & quoted form of POSIX path of (choose file)) as integer

Thanks for your support, Adam,
time is short, help is valuable.

For the du command, I believe you need to use the -k option, not the -d option to get the file size in 1024 byte blocks:

--Choosing a file that Finder displays as 1.3 MB in size (1,363,732 bytes)

set tSize to first word of (do shell script "du -d 0 " & quoted form of POSIX path of (choose file)) as integer

--> 2664

set tSize to first word of (do shell script "du -k " & quoted form of POSIX path of (choose file)) as integer

--> 1332

Hi, Craig!

-d stands for deep, and the 0 for the subfolders; -m stands for Megabyte. I look forward to read a bit the man-pages.

	set tSize to first word of (do shell script "du -m -d 0 " & quoted form of POSIX path of (E_path as alias)) as integer

Hmm…shell scripts…very efficient and small, but i’ve no time to learn other computer languages, sob. Its good to stay within the community of Macscripter.

How about the -h option (return result in human readable form; xxK for xx kilobytes, xxM for xx megabytes, etc.

set tSize to first word of (do shell script "du -h " & quoted form of POSIX path of (choose file))