Re: remove suffix
Re: remove suffix
- Subject: Re: remove suffix
- From: JollyRoger <email@hidden>
- Date: Thu, 27 Sep 2001 06:36:47 -0500
On 9/27/2001 2:31 AM, "email@hidden" <email@hidden>
wrote:
>
I have a script that copies htm files and adds some code in them. I need to
>
add some code to this script that removes the old suffix on each file.
>
>
example:
>
Filename = myfile.htm
>
New filename = myfile
>
>
This is probably very easy to do but I dont know how to write the
>
applescript code to remove ".htm" of the filename. Today I use
>
filemanipulator to do this, but it is one extra step. So it would be great
>
to have this function in the script.
I see Paul has already answered. But I thought I'd offer this up. I use
this function in my scripts. This function separates the filename from the
extension regardless of the number of characters in the extension.
log my SeparateFilenameFromExtension("Some Filename.jpeg")
on SeparateFilenameFromExtension(filename)
set saveDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"."}
set leftSide to item 1 of the text items of filename
set rightSide to item 2 of the text items of filename
set AppleScript's text item delimiters to saveDelims
return {leftSide, rightSide}
end SeparateFilenameFromExtension
A caveat: The function assumes there is only period in the file name. Maybe
one day I'll rewrite it to deal with multiple periods. So far it hasn't
caused me any problem the way it is.
HTH
JR