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
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
-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.