RE: remove suffix
RE: remove suffix
- Subject: RE: remove suffix
- From: Nigel Garvey <email@hidden>
- Date: Fri, 28 Sep 2001 14:26:51 +0100
In my message of Friday, 28 September 2001 11:25:59 (BST), I wrote:
>
All of the suggestions so far assume that the file name actually *has* a
>
suffix, but in the context of the original enquiry, that's probably OK.
>
However, how about this?
>
>
on stripFileSuffix from aString
>
set AppleScript's text item delimiters to {":"}
>
if text item -1 of aString contains "." then
>
set AppleScript's text item delimiters to {"."}
>
set aString to text 1 thru text item -2 of aString
>
end if
>
set AppleScript's text item delimiters to {""}
>
return aString
>
end stripFileSuffix
>
>
stripFileSuffix from "My disk:my folder.suffix:my file.suffix"
Or, since I mentioned the original context:
on unSuffixedFilename from aPath -- takes an alias, a file name, or a
path string
set aPath to aPath as string
if aPath ends with ":" then
error "The item \"" & aPath & "\" isn't a file!"
end if
set AppleScript's text item delimiters to {":"}
set filename to text item -1 of aPath
if filename contains "." then
set AppleScript's text item delimiters to {"."}
set newname to text 1 thru text item -2 of filename
else
set newname to filename
end if
set AppleScript's text item delimiters to {""}
if newname is "" then
error "The file name \"" & filename & "\" has no prefix!"
end if
return newname
end unSuffixedFilename
set newName to unSuffixedFilename from choose file
NG