Re: Getting the name of a file from an "alias"
Re: Getting the name of a file from an "alias"
- Subject: Re: Getting the name of a file from an "alias"
- From: Devon and Cornwall <email@hidden>
- Date: Mon, 11 Jun 2001 18:07:05 -0700
At 11:15 PM +0200 6/11/01, Jan Pieter Kunst wrote:
>
Greetings,
>
>
I'm sure this must be extremely simple, but I can't find the answer.
>
>
Let's say I have an variable x in my script that is set to an "alias". So,
>
the value of x is:
>
>
alias "Disk:folder1:folder2:file"
>
>
How do I get just the name of the file (in the above case "file") into a
>
string?
You could ask the Finder.
set Good to choose file
tell application "Finder" to name of Good
or have at it with TIDs. This example returns a parent path to a file. You can probably divine how to extract a file name by looking at it.
set c to choose file
extractParentPath(c)
on extractParentPath(f)
set {oldTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
if (f as string)'s last text item is "" then --its a folder (null string follows last colon)
try
set ItmsparentPath to "" & text items 1 thru -3 of (f as string) & ":"
on error --its a disk
set ItmsparentPath to f as string
end try
else --its a file
set ItmsparentPath to "" & text items 1 thru -2 of (f as string) & ":"
end if
set AppleScript's text item delimiters to oldTID
return ItmsparentPath
end extractParentPath
Devon