• 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: Getting the length of a file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting the length of a file


  • Subject: Re: Getting the length of a file
  • From: has <email@hidden>
  • Date: Fri, 14 Jan 2005 12:01:39 +0000

Emile Schwarz wrote:

I have troubles with the following code who do not returns the file size in an Integer (or Real) format.
[...]
I get:
AppleScriptFinderGuide.PDF 6,7982E+4

6,7982E+4 is a real. AppleScript automatically displays large and small real values using scientific notation. Presumably what you mean is you'd like it to format this number as "67982,0" or "67982".


- Option 1: If it's a whole number within range +/-500 000 000 (the max/min size of AS's integer type), just cast it to an integer which AS will display using standard notation:

tell application "Finder"
set {itemName, itemLength} to {name, size} of item 1 of front Finder window
end tellas integer)
--> "Library.scpt 78896"



- Option 2: If it's a non-whole number or can't be sure it lies within +/-5e8 (AS reals can lie within +/-1e300) then use a suitable formatting routine, e.g. the numToText handler in AppleMods' Number library:


-- [snip auto-generated library loading code [1]]
tell application "Finder"
set {itemName, itemLength} to {name, size} of item 1 of front Finder window
end tell
if itemLength is not missing value then
set itemLength to _Number's numToText(itemLength, ",")
end if
return itemName & tab & itemLength
--> "Library.scpt 78896"



has

[1] If you've not used AppleMods' libraries before, you'll need to download and install AppleMods' Loader system first <http://applemods.sourceforge.net/getstarted.html>. Run the Loader installer, then download and add the Number library to the ASLibraries folder. Use the LoaderWizard applet to generate the library loading code to paste at the top of your script.
--
http://freespace.virgin.net/hamish.sanderson/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Prev by Date: RE: Tar/gzip is messing up icons
  • Next by Date: ps2pdf -->strange behavior
  • Previous by thread: Getting the length of a file
  • Next by thread: ps2pdf -->strange behavior
  • Index(es):
    • Date
    • Thread