Re: Replacing characters in filenames
Re: Replacing characters in filenames
- Subject: Re: Replacing characters in filenames
- From: Chris Nebel <email@hidden>
- Date: Tue, 16 Jan 2001 18:17:00 -0800
- Organization: Apple Computer, Inc.
Michelle Steiner wrote:
>
On 1/16/01 12:11 PM, Peter Huxmann <email@hidden> wrote
>
>
>Is there an easy way to change characters in file names? Specifically, I'm
>
>trying to write a droplet that will replace spaces in file names with
>
>underscores. (Goddamn internet!)
>
>
to replaceSpaces(instring)
>
...
>
end replaceSpaces
Alternatively, you have the obligatory text item delimiters solution:
on munge(s)
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set x to every text item of s
set AppleScript's text item delimiters to "_"
set r to x as string
set AppleScript's text item delimiters to tid
return r
end munge
munge("This is a test") --> "This_is_a_test"
(AppleScript's text item delimiters! They slice! They dice! They even make julienne
fries!)
Of course, if we actually supported object model operations on strings, you could just say
'set every character of s where it is " " to "_"'. We're working on it. Really.
--Chris Nebel
AppleScript Engineering