File/folder name cleanup droplet
File/folder name cleanup droplet
- Subject: File/folder name cleanup droplet
- From: Brett Conlon <email@hidden>
- Date: Mon, 14 Aug 2006 19:49:57 +1100
Hi all,
Recently there was discussion on the
list about using a file name cleanup script.
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.
Here's the script:
property
myListOfChar : {"/", "?", "|", "*",
"<", ">", "\""} --last entry
is for a single quote "
property
myReplacementChar : {"-", "", "_", "_",
"_", "_", "'"} --last entry quote replaced
by an apostrophe
on
run
tell
application "Finder"
set
myList to
navchoose object with prompt "Choose folder." with
multiple files
set
FailedFolderNames to
{}
set
FailedFileNames to
{}
repeat
with
i in
myList
set
allItems to
entire contents of
i
repeat
with
ThisItem in
allItems
if
class of
ThisItem is
folder then
set
folderList to
my
CheckFolders(ThisItem, FailedFolderNames)
else
if
class of
ThisItem is
document file then
set
filelist to
my
CheckFiles(ThisItem, FailedFileNames)
end
if
end
repeat
end
repeat
display dialog "These are the failed
items that were changed:" & return & return & "Folders:"
& return & return & FailedFolderNames & return & return
& "Files:" & return & return & FailedFileNames
end
tell
end
run
on
open (myList)
--
was in too much of a hurry to write this yet.
end
open
on
CheckFiles(ThisItem, FailedFileNames)
tell
application "Finder"
repeat
with
aChar in
myListOfChar
if
aChar is
in
(name of
ThisItem) then
set
end
of
FailedFileNames to
name of
ThisItem
set
myNewString to
change myListOfChar into myReplacementChar in (name of
ThisItem) as
string
set
the
name of
ThisItem to
myNewString
return
FailedFileNames
end
if
end
repeat
end
tell
end
CheckFiles
on
CheckFolders(ThisItem, FailedFolderNames)
tell
application "Finder"
repeat
with
aChar in
myListOfChar
if
aChar is
in
(name of
ThisItem) then
set
end
of
FailedFolderNames to
name of
ThisItem
set
myNewString to
change myListOfChar into myReplacementChar in (name of
ThisItem) as
string
set
the
name of
ThisItem to
myNewString
return
FailedFolderNames
end
if
end
repeat
end
tell
end
CheckFolders
I guess it would work properly if it
worked from the bottom-up but then again there may be a much better way
of attacking it.
BTW, I'll also be adding a delimiter
to break up the failed file and folder names list in the end dialog.
As a side note, I copied this to my
10.3.9 OSX Server Mac to run it on a big list of folders but it just wouldn't
run. I had copied the satimage.osax file to ScriptAdditions (tried both
root Library and Users Lib) and it kept erroring. When I opened the script
the satimage cose was in raw code (whatever you call that). I tried double
clicking on the satimage.osax file to activate it and a reboot did nothing.
Any thoughts?
Many thanks,
Cojcolds _______________________________________________
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