Re: Renaming files/folders
Re: Renaming files/folders
- Subject: Re: Renaming files/folders
- From: Paul Skinner <email@hidden>
- Date: Wed, 05 Sep 2001 12:06:24 -0400
on 9/5/01 9:29 AM, Michelle Steiner wrote:
>
On 9/4/01 11:31 PM, Ray Phillips <email@hidden> wrote:
>
>
> I've written a script for a droplet which alters the names of any files and
>
> folders (and their contents) which are dragged onto it so the become valid
>
> for a FAT file system. (It removes any trailing spaces and periods, and
>
> replaces any of these characters \ / * ? \ " < > | with '-'.)
>
>
That shouldn't take a 200-line script. Here's a much shorter one that
>
should do what you need. I haven't tested it, though.
>
>
--Michelle
>
>
on open (DroppedItems)
>
set the filestochange to the files of the DroppedItems
>
repeat with thisFile in filestochange
>
tell application "Finder"
>
set the NameToChange to the name of thisFile
>
end tell
>
set tid to text item delimiters
>
change(NameToChange, "\\")
>
change(NameToChange, "/")
>
change(NameToChange, "*")
>
change(NameToChange, "?")
>
change(NameToChange, "\"")
>
change(NameToChange, "<")
>
change(NameToChange, ">")
>
change(NameToChange, "|")
>
set text item delimiters to tid
>
tell application "Finder"
>
set the name of thisFile to the NameToChange
>
end tell
>
end repeat
>
end open
>
>
on change(inString, inChar)
>
set text item delimiters to the inChar
>
set tempList to text items of the inString
>
set text item delimiters to "-"
>
set the outstring to tempList as text
>
return the outstring
>
end change
>
----------------------------------------------------------------------
>
| Michelle Steiner | We're not human beings having a spiritual |
>
| | experience. We're spiritual beings |
>
| email@hidden | having a human experience. |
>
----------------------------------------------------------------------
'Handlerized'. Tested. Removes trailing spaces in the filenames.
--begin script
on open (DroppedItems)
repeat with thisfile in DroppedItems as list
set thisfile to thisfile as text
if character -1 of thisfile is not ":" then
tell application "Finder"
set the NameToChange to the name of file thisfile
set the name of file thisfile to my filter(NameToChange)
end tell
end if
end repeat
end open
on filter(inString)
repeat while character -1 of inString is " " --remove trailing spaces.
set inString to (characters 1 thru -2 of inString) as text
end repeat
set tid to AppleScript's text item delimiters
set filterList to {"\\", "/", "+", "?", "\"", "<", ">", "|", "."}
repeat with thisFilter in filterList
set text item delimiters to thisFilter as text
set inString to text items of inString
set text item delimiters to "-"
set the inString to inString as text
end repeat
set AppleScript's text item delimiters to tid
return the inString
end filter
--end script
--
"The more prohibitions there are, The poorer the people will be"
-Lao Tse