Re: Deleting characters
Re: Deleting characters
- Subject: Re: Deleting characters
- From: Nigel Garvey <email@hidden>
- Date: Fri, 13 Feb 2004 10:11:58 +0000
Hanaan Rosenthal wrote on Thu, 12 Feb 2004 12:37:32 -0500:
>
Ian,
>
I didn't know of a script, that is, until I wrote one:
>
>
set theFolderPath to "path:to:folder:"
>
set listOfCharactersToDelete to {space, "/"}
>
>
repeat with theCharacter in listOfCharactersToDelete
>
deleteCharacterFromNameName((theCharacter as string), theFolderPath)
>
end repeat
>
>
on deleteCharacterFromNameName(theCharacter, theFolderPath)
>
tell application "Finder"
>
set fileList to name of every file of folder theFolderPath whose name
>
contains theCharacter
>
repeat with i from 1 to (count fileList)
>
set oldName to (item i of fileList)
>
set AppleScript's text item delimiters to theCharacter
>
set theTextItems to text items of oldName
>
set AppleScript's text item delimiters to ""
>
set newName to theTextItems as string
>
set name of file (theFolderPath & oldName) to newName
>
end repeat
>
end tell
>
end deleteCharacterFromNameName
May I suggest looping through the characters-to-delete with each file
name, rather than vice versa? This will reduce the number of disk
accesses and thus the time taken:
set theFolderPath to "path:to:folder:"
set listOfCharactersToDelete to {space, "/"}
deleteCharactersFromNameName(listOfCharactersToDelete, theFolderPath)
on deleteCharactersFromNameName(theCharacters, theFolderPath)
set nChrs to (count theCharacters)
set astid to AppleScript's text item delimiters
tell application "Finder" to set fileList to (name of every file of
folder theFolderPath) as list
repeat with i from 1 to (count fileList)
set oldName to (item i of fileList)
set newName to oldName
repeat with j from 1 to nChrs
set AppleScript's text item delimiters to item j of theCharacters
set theTextItems to text items of newName
set AppleScript's text item delimiters to ""
set newName to theTextItems as string
end repeat
if newName is not oldName then
tell application "Finder" to set name of file (theFolderPath &
oldName) to newName
end if
end repeat
set AppleScript's text item delimiters to astid
end deleteCharactersFromNameName
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.