• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: File size
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: File size


  • Subject: Re: File size
  • From: Christopher Nebel <email@hidden>
  • Date: Sun, 5 May 2002 20:40:39 -0700

On Friday, May 3, 2002, at 02:28 PM, Andy Wylie wrote:

on Chew(Chomp)
set {bytes, cnt} to {{"bytes", "kB", "mB", "gB", "tB", "pB", "eB"}, 0}
repeat until Chomp < 1024
set {Chomp, cnt} to {Chomp / 1024, cnt + 1}
end repeat
tell Chomp to return ((it div 1) + (it mod 1) * 100 div 1 * 0.01) &
bytes's item (cnt + 1) as string
end Chew

tell application "Finder" to set |size| to largest free block
Chew(|size|)
-- "37.89mB"

Very good, but the correct suffixes are either kB, MB, GB, TB, PB and EB or KiB, MiB, GiB, TiB, PiB, and EiB, depending on whether you're a traditionalist or a squeaky-clean SI citizen. (Most computer systems, including Mac OS, use "KB" for kilobytes (actually kibibytes), which is doubly technically wrong but pretty darn well entrenched.) See http://physics.nist.gov/cuu/Units/prefixes.html and http://physics.nist.gov/cuu/Units/binary.html for all the painful details.


--Chris Nebel
AppleScript Engineering
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: File size (From: Andy Wylie <email@hidden>)

  • Prev by Date: Re: Choose from list
  • Next by Date: Re: Choose from list
  • Previous by thread: Re: File size
  • Next by thread: Re: File Size
  • Index(es):
    • Date
    • Thread