Re: Renaming files in Finder: why so slow?
Re: Renaming files in Finder: why so slow?
- Subject: Re: Renaming files in Finder: why so slow?
- From: Nigel Garvey <email@hidden>
- Date: Sun, 31 Aug 2003 11:07:53 +0100
"Bob.Kalbaugh" wrote on Sat, 30 Aug 2003 17:33:07 -0500:
"Bob.Kalbaugh" wrote on Sat, 30 Aug 2003 17:33:07 -0500:
>
I'm attempting to script the renaming of folders and files. I want to
>
replace spaces with an underscore. I want recursion. I've created a droplet
>
that works, but it's very s l o w. It took about 30 seconds for a folder
>
containing about 35 files and folders OMM.
>
>
OS9 on a PowerPC 7300 - AS v1.4
>
>
Is there a way to speed up this script?
Then later:
>
For anyone else interested the final script follows. Athough it is still
>
fairly sluggish on my (6 year old computer) it may prove faster on newer
>
machines. If someone has any suggestions for making it faster I'd be happy
>
to hear it.
What takes most of the time in this sort of script is accessing the items
on the disk. Keeping the number of accesses down is what will make the
most noticeable difference. The following works with OS 9.2.2 - but
probably not with X. It could possibly be improved, but it's faster than
your posted "final" version on my test hierarchy. However, this may
depend on what's actually in the folders. :-)
on open fileList
tell application "Finder" to activate
doUnderScore(fileList)
end open
on doUnderScore(theList)
tell application "Finder"
set oldTIDs to AppleScript's text item delimiters
considering case -- for faster string comparisons
try -- treating theList as a Finder reference, fails at top level
set theList to (theList's folders as list) & (theList's files
whose name contains " ")
end try
repeat with thisItem in theList
set AppleScript's text item delimiters to {":"}
set {otherCandidate, itemName} to text items -2 thru -1 of
(thisItem as string)
if (count itemName) is 0 then -- thisItem is a folder
set itemName to otherCandidate
my doUnderScore(thisItem)
end if
-- Only change the name if necessary
if itemName contains " " then
set AppleScript's text item delimiters to {" "}
set itemName to itemName's text items
set AppleScript's text item delimiters to {"_"}
set name of thisItem to (itemName as string)
end if
end repeat
end considering
set AppleScript's text item delimiters to oldTIDs
end tell
end doUnderScore
NG
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.