• 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: Michelle Steiner <email@hidden>
  • Date: Tue, 16 Jan 2001 13:25:37 -0800

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!)

on open (filelist)
repeat with pathname in the filelist
tell application "Finder" to set filename to name of (file (pathname as
text))
set the NewName to replaceSpaces(filename)
tell application "Finder" to set the name of pathname to the NewName
end repeat
end open

to replaceSpaces(instring)
set the Pos to offset of space in instring
if the Pos is 0 then
return instring
else if the Pos is 1 then
set instring to "_" & rest of instring
else if the Pos is length of instring then
set instring to text 1 through -2 of instring & "_"
else
set instring to text 1 through (Pos - 1) of instring ,
& "_" & text (Pos + 1) through -1 of instring
end if
replaceSpaces(instring)
end replaceSpaces

--Michelle

----------------------------------------------------------------------
| Michelle Steiner | Hard as it may be to believe, my |
| email@hidden | life has been based on a true story. |
----------------------------------------------------------------------


  • Follow-Ups:
    • Re: Replacing characters in filenames
      • From: Chris Nebel <email@hidden>
  • Prev by Date: Re: Replacing characters in filenames
  • Next by Date: Re: properties as strings
  • Previous by thread: Re: Replacing characters in filenames
  • Next by thread: Re: Replacing characters in filenames
  • Index(es):
    • Date
    • Thread