• 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: "Christopher C. Stone" <email@hidden>
  • Date: Tue, 16 Jan 2001 14:59:46 -0600

At 01/16/2001 14:11 -0600, Peter Huxmann wrought:

> Okay, so I'm kinda new to this whole Applescript thing, too, but I've tried
> everything I can think of & can't seem to figure this one out:
>
> 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!)
___________________________________________________________________________

Hello Peter,

You're right. The answer *is* simple, but it's not something an AppleScript newbie would ever think of. So don't feel bad.

---------------------------------------------------------------------------
set fname to "This is a file.txt"

if fname contains " " then
set AppleScript's text item delimiters to {" "}
set fname to text items of fname
set AppleScript's text item delimiters to {"_"}
set fname to fname as string
set AppleScript's text item delimiters to {""}
end if

fname
---------------------------------------------------------------------------

A Scripting Addition (osax) alternative would be to use Leonard Rosenthol's RegEx Commands:

http://www.lazerware.com/FTP/RECommands.hqx

---------------------------------------------------------------------------
set fname to "This is a file.txt"

set fname to REReplace fname with "_" pattern " "
---------------------------------------------------------------------------


Best Regards,

Christopher Stone
______________________________
StoneWorks Computer Consulting
email@hidden


References: 
 >Replacing characters in filenames (From: Peter Huxmann <email@hidden>)

  • Prev by Date: Re: Replacing characters in filenames
  • Next by Date: Re: Replacing characters in filenames
  • Previous by thread: Re: Replacing characters in filenames
  • Next by thread: Re: Replacing characters in filenames
  • Index(es):
    • Date
    • Thread