Re: File/folder name cleanup droplet
Re: File/folder name cleanup droplet
- Subject: Re: File/folder name cleanup droplet
- From: kai <email@hidden>
- Date: Thu, 17 Aug 2006 04:54:59 +0100
On 16 Aug 2006, at 03:37, Brett Conlon wrote:
Today I had urgent need of a file & folder cleanup script. So I
wrote the below script referencing some of the suggestions made to
the list. I think what I have is clunky-as but it is kinda working.
The issue is that I think it is initially obtaining a list of file/
folder names, then fixing them from the top-down which means when
it is trying to access the deeper-down folders in the obtained list
it is throwing an error coz it can no longer find them.
That's about the size of it, Coj.
One way to keep track of the name changes is to use aliases of any
folders, rather than Finder references - perhaps something like this:
--------
(* requires Satimage.osax *)
property myListOfChar : {"/", "?", "|", "*", "<", ">", "\""} --last
entry is for a single quote "
property myReplacementChar : {"-", "", "_", "_", "_", "_", "'"} --
last entry quote replaced by an apostrophe
on results_summary for {renamedFiles, renamedFolders}
set reportFiles to (count renamedFiles) > 0
set reportFolders to (count renamedFolders) > 0
if not (reportFiles or reportFolders) then return "No name changes
were necessary."
set msg to "The following names were changed:"
set tid to text item delimiters
set text item delimiters to return & tab
if reportFiles then set msg to msg & return & return & {"Files:",
"", ""} & renamedFiles
if reportFolders then set msg to msg & return & return &
{"Folders:", "", ""} & renamedFolders
set text item delimiters to tid
msg
end results_summary
to check_items from itemList against renamedList
tell application "Finder" to repeat with currItem in itemList
set currName to currItem's name
set newName to change myListOfChar into myReplacementChar in currName
if newName is not currName then
set renamedList's end to currName
set currItem's name to newName
end if
end repeat
end check_items
to process_folders from mainFolderList against {renamedFiles,
renamedFolders}
tell application "Finder" to repeat with mainFolder in mainFolderList
set allItems to (a reference to mainFolder's entire contents)
if (count document files of allItems) > 0 then ¬
my (check_items from (get document files of allItems) against
renamedFiles)
set folderCount to count folders of allItems
if folderCount is 0 then
set folderList to {}
else if folderCount is 1 then
set folderList to folders of allItems as alias as list
else
set folderList to folders of allItems as alias list
end if
set folderList's end to mainFolder's contents (* optional: include
top-level folder *)
my (check_items from folderList against renamedFolders)
end repeat
end process_folders
to process_items from itemList
set mainFileList to {}
set mainFolderList to {}
set renamedFiles to {}
set renamedFolders to {}
tell application "Finder" to repeat with currItem in itemList
set currClass to item currItem's class
if currClass is document file then
set mainFileList's end to currItem's contents
else if currClass is folder then
set mainFolderList's end to currItem's contents
end if
end repeat
check_items from mainFileList against renamedFiles
process_folders from mainFolderList against {renamedFiles,
renamedFolders}
display dialog (results_summary for {renamedFiles, renamedFolders})
buttons "OK" default button 1
end process_items
to open itemList
process_items from itemList
end open
to run
process_items from navchoose object with prompt ¬
"Choose folders or files to check/rename:" with multiple files
end run
--------
---
kai
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden