Re: Replacing characters in filenames
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. |
----------------------------------------------------------------------