Re: Renaming Files
Re: Renaming Files
- Subject: Re: Renaming Files
- From: monk <email@hidden>
- Date: Fri, 27 Jul 2001 01:06:38 -0400
-- 7/26/01 09:36 pm: email@hidden said:
>
I have what I hope is a simple question:
>
>
I want to be able to take SimpleText pictures and convert their file
>
names to include a suffix (.PICT, .GIF, .JPEG) so they can be readily
>
uploaded for use in a web page. I am trying to figure out how I can
>
do the entire folder in one script. So far I am not having much
>
luck. Any ideas?
>
here:
<script>
-- ADD PREFIX/SUFFIX TO FILES
-- )1998 Sal Soghoian, Apple Computer
tell application "finder"
activate
set the chosen_folder to (choose folder with prompt "Pick the folder
containing the files to rename:")
set the prefix_or_suffix to ""
repeat
display dialog "Enter the prefix or suffix to use:" default answer
the prefix_or_suffix buttons {"Cancel", "Prefix", "Suffix"}
copy the result as list to {the prefix_or_suffix, the
button_pressed}
if the prefix_or_suffix is not "" then exit repeat
end repeat
set the file_list to (every file of the chosen_folder) as list
repeat with this_file in the file_list
if the button_pressed is "Prefix" then
set the new_file_name to the (the prefix_or_suffix & name of
this_file) as string
else
set the new_file_name to the (name of this_file & the
prefix_or_suffix) as string
end if
my set_item_name(this_file, the new_file_name)
end repeat
end tell
beep 2
on set_item_name(this_item, new_item_name)
tell application "finder"
activate
set the parent_container_path to (the container of this_item) as
text
if not (exists file (the parent_container_path & new_item_name))
then
try
set the name of this_item to new_item_name
on error the error_message number the error_number
if the error_number is -59 then
set the error_message to "This name contains improper
characters, such as a colon (:)."
else --the suggested name is too long
set the error_message to "The name is more than 31
characters long."
end if
beep
display dialog the error_message default answer
new_item_name buttons {"Cancel", "Skip", "OK"} default button 3
copy the result as list to {new_item_name, button_pressed}
if the button_pressed is "Skip" then return 0
my set_item_name(this_item, new_item_name)
end try
else --the name already exisits
beep
display dialog "This name is already taken, please rename."
default answer new_item_name buttons {"Cancel", "Skip", "OK"} default button
3
copy the result as list to {new_item_name, button_pressed}
if the button_pressed is "Skip" then return 0
my set_item_name(this_item, new_item_name)
end if
end tell
end set_item_name
<script>
i also have one for folders i you'd like
h 'monk' elmer
--
http://www.assemblage.org