Hi,
I never used AppleScript but now I have a problem where I could really need it. I have to trim the filenames of about 100,000 files which are placed in 400 different folders. With the script “Trim filenames” from Apple I am only able access all files from one folder but of course I would like to access all 400 folders. I have spent some time now but I could not figure it out. :oops:
Any suggestions :?:
Christian
Code:
try
tell application “Finder” to set the source_folder to (folder of the front window) as alias
on error – no open folder windows
set the source_folder to path to desktop folder as alias
end try
repeat
display dialog “Text to trim from every file name:” default answer “” buttons {“Cancel”, “Trim Start”, “Trim End”}
copy the result as list to {the text_to_trim, the button_pressed}
–if the button_pressed is “Cancel” then return “user cancelled”
if the text_to_trim is not “” then exit repeat
end repeat
set the character_count to the number of characters of the text_to_trim
set the item_list to list folder source_folder without invisibles
set source_folder to source_folder as string
repeat with i from 1 to number of items in the item_list
set this_item to item i of the item_list
set this_item to (source_folder & this_item) as alias
set this_info to info for this_item
if folder of this_info is false then
set the current_name to the name of this_info
if the button_pressed is “Trim Start” then
if the current_name begins with the text_to_trim then
set the new_name to (characters (the character_count + 1) thru -1 of the current_name) as string
set_item_name(this_item, new_name)
end if
else
if the current_name ends with the text_to_trim then
set the new_name to (characters 1 thru -(the character_count + 1) of the current_name) as string
set_item_name(this_item, new_name)
end if
end if
end if
end repeat
beep 2
:oops: