• 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 path info
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: File path info


  • Subject: Re: File path info
  • From: Zachary Smestad <email@hidden>
  • Date: Mon, 1 Mar 2004 19:44:38 -0600

On Mar 01, 2004, at 06:43 PM, Walter Ian Kaye wrote:

At 03:27p -0800 03/01/2004, Duane Mitchell didst inscribe upon an electronic papyrus:

Hello,

I'm an AppleScript newbie and have a basic question on file specs.

I am using the choose file scripting addition command to set a variable for a chosen file. I'd like to know how I can get the name of the folder that a file is in from the file spec: alias "MacHD:Folder1:File".

One possible way would be to ask the Finder for its container:

tell app "Finder" to set c to (container of myAlias) as alias

Another way would be to split on the colons and reconstruct.

Also, if there is any other useful info that I could get from this basic file spec that would be appreciated.

Check out the 'info for' command in Standard Additions, and the 'POSIX path' property. And the properties for file and item in the Finder.


-boo

If it's just the folder name (not entire folder path), this works (the efficient way- I think...):

set text item delimiters to ":" --make that "AppleScript's text item delimiters" if within a tell block
set folderName to text item -2 of (thePath as string)
set text item delimiters to ""

or if you want a one-liner (the fun way):

set folderName to do shell script "/usr/bin/basename `/usr/bin/dirname '" & POSIX path of (theFile as string) & "'`"

I guess my habit is to avoid the Finder as much as possible.

Zach
_______________________________________________
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: 
 >File path info (From: Duane Mitchell <email@hidden>)
 >Re: File path info (From: Walter Ian Kaye <email@hidden>)

  • Prev by Date: Re(2): Folder size
  • Next by Date: Auto field fill-in for Safari?
  • Previous by thread: Re: File path info
  • Next by thread: Re: File path info
  • Index(es):
    • Date
    • Thread