Re: Renaming files/folders
Re: Renaming files/folders
- Subject: Re: Renaming files/folders
- From: "Bob.Kalbaugh" <email@hidden>
- Date: Wed, 05 Sep 2001 11:32:12 -0500
on 9/5/01 8:29 AM, Michelle Steiner at email@hidden wrote:
>
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
Hi Michelle,
I'm not the original poster of this thread, but I also happen to be working
on a script that alters the names of files, so I tested your script because,
well, you always post great stuff. :-) At any rate I found that I needed to
make one slight change to get the script to work. The script kept passing
the handler the original nameToChange variable for some reason.
Here's the result of what was happening before I modified your script.
(Note that I altered it to work on a selection from the Finder instead of
"on open" and logged the outstring on each run of the handler.)
--result
tell application "Finder"
get selection
--> {file "my /file/ <test>" of folder "Name Test"}
get name of file "my /file/ <test>" of folder "Name Test"
--> "my /file/ <test>"
(*my /file/ <test>*)
(*my -file- <test>*) -- it did change it!
(*my /file/ <test>*)
(*my /file/ <test>*)
(*my /file/ <test>*)
(*my /file/ -test>*) -- changed it!
(*my /file/ <test-*) -- changed it!
(*my /file/ <test>*)
set name of file "my /file/ <test>" of folder "Over*Score_Test" to "my
/file/ <test>"
end tell
So for every instance of calling the handler...
>
change(NameToChange, "whatever")
I changed it to...
set NameToChange to change(NameToChange, "whatever")
It works great! Thanks for your Post.
--
bob.kalbaugh
>
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