• 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: Emmanuel <email@hidden>
  • Date: Tue, 2 Mar 2004 07:36:48 +0100

At 7:44 PM -0600 01/03/04, Zachary Smestad wrote:
>>>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.
>
>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) & "'`"

Finally, when you have the Satimage osax installed, the fastest will be (assuming that the_path contains the string):

find text ":([^:]+):?$" in the_path with regexp and string result using "\\1"

(that one works for folders and for files)

Emmanuel
_______________________________________________
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: Escape URL characters for shell
  • Next by Date: Text parsing
  • Previous by thread: Re: File path info
  • Next by thread: Re: File path info
  • Index(es):
    • Date
    • Thread