Re: script to remove spaces and text in multiple file names
Re: script to remove spaces and text in multiple file names
- Subject: Re: script to remove spaces and text in multiple file names
- From: "Marc K. Myers" <email@hidden>
- Date: Mon, 26 Aug 2002 03:23:38 -0400
- Organization: [very little]
>
Date: Sun, 25 Aug 2002 20:00:29 -0400
>
Subject: script to remove spaces and text in multiple file names
>
From: Michael Caporale <email@hidden>
>
To: email@hidden
>
>
I am not currently using applescript, but I have been told it would be
>
helpful in automating a repetitive task that I need t o accomplish
>
tomorrow.
>
>
I have 8,000 documents in folders that have spaces in their names that
>
need to be removed. Also I need to remove specific recurring text, such
>
as the word "copy"
>
>
Can anyone tell me how to write a script to do this?
This is untested code (other than the textReplace handler), but it
should give you some idea of how to proceed:
on open (theItems)
repeat with anItem in theItems
if (anItem as text) ends with ":" then
procFldr(anItem)
else
procFile(anItem)
end if
end repeat
end open
on procFldr(aFldr)
tell application "Finder"
set fileList to files of aFldr
repeat with aFile in fileList
tell me to procFile(aFile)
end repeat
set fldrList to folders of aFldr
repeat with someFldr in fldrList
tell me to procFldr(someFldr)
end repeat
end tell
end procFldr
on procFile(aFile)
tell application "Finder"
set theFile to (aFile as alias)
set fileName to name of theFile
end tell
set newName to textReplace(fileName, " ", "")
set newName to textReplace(newName, " copy", "")
-- insert as many find/replace lines as are needed
if fileName is not newName then
tell application "Finder"
set name of theFile to newName
update theFile
end tell
end if
end procFile
on textReplace(theText, srchStrng, replStrng)
tell (a reference to AppleScript's text item delimiters)
set {od, contents} to {contents, {srchStrng}}
try
set {textList, contents} to {(text items of theText), {replStrng}}
set {newText, contents} to {(textList as text), od}
return item 1 of result
on error errMsg number errNbr
set contents to od
error errMsg number errNbr
end try
end tell
end textReplace
Marc K. Myers <email@hidden>
http://AppleScriptsToGo.com
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074
[8/26/02 3:18:31 AM]
_______________________________________________
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.