Re: File path info
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.