• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Replacing characters in filenames
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Replacing characters in filenames
      • From: Timothy Bates <email@hidden>
    • Re: Replacing characters in filenames
      • From: Paul Berkowitz <email@hidden>
References: 
 >Re: Replacing characters in filenames (From: Michelle Steiner <email@hidden>)

  • Prev by Date: Re: properties as strings
  • Next by Date: Re: 'to' as a handler parameter label
  • Previous by thread: Re: Replacing characters in filenames
  • Next by thread: Re: Replacing characters in filenames
  • Index(es):
    • Date
    • Thread