Re: Replace characters in filename
Re: Replace characters in filename
- Subject: Re: Replace characters in filename
- From: Nigel Smith <email@hidden>
- Date: Mon, 14 Jun 2004 14:05:36 +0100
On 12/6/04 20:49, "Rick Davis" <email@hidden> wrote:
>
How would I find certain characters (any of a list of 13) in a filename
>
and replace them with one common character?
This function will return either false -- for a string with no dodgy
characters -- or the string with all dogy characters replaced with a "-".
You'll have to edit the "badChars" string to suit your situation -- remember
to put the most commonly found badChars to the front of the string:
on changeChars(aString)
set badChars to "!@#$%^&*()?<>"
set tmp to ""
repeat with x from 1 to 13
if aString contains character x of badChars then
repeat with y from 1 to count of aString
if character y of aString is not in badChars then
set tmp to tmp & character y of aString
else
set tmp to tmp & "-"
end if
end repeat
return tmp
end if
end repeat
return false
end changeChars
How you get/change the filenames themselves will depend on your situation.
Pick a file from a dialog? Process a folder (do you want subfolders as
well?) from a pick list or droplet?
And if this is to do multiple files, what about error-checking -- what
should happen if "hello&world" and "hello*world" are present in the same
folder?
Those need to be answered before you can do much with changeChars(), but at
least it might get you started.
HTH,
Nigel
_______________________________________________
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.