Problem with odd characters in folder names

Hi

I have looked everywhere in this forum, and haven’t found any solution to my problem. My problem is that I have a folder on my server that every now and then get pictures copied to it. The pictures themselfes lies in folders, i.e.
~/Desktop/Pictures in/TEST/pic1.jpg, pic2.jpg and so forth

The problem is that the folder “TEST” sometimes get odd characterz like “µ”, “√”, “¢” and others. I would like to get rid of those and replace them with lets say “a” or “o”.

Would someone please help me in this matter?

TIA
-arndorff a.k.a Pichard

Hi

You probably need to be using something called text item delimeters to replace characters!
Heres an example:

set theText to "pictur foldr"
set OldDelims to AppleScript's AppleScript's text item delimiters
set AppleScript's AppleScript's text item delimiters to ""
set newText to text items of theText
set AppleScript's AppleScript's text item delimiters to "e"
set newText to newText as text
set AppleScript's AppleScript's text item delimiters to OldDelims
return newText

I would be inclined to use Nigel Garvey’s FindAndReplace version because it is nestable (can be called in its own argument so that more than one find/replace can be accomplished in a single line like

set myNewText to findAndReplace(toFindA, replaceWithB, my findAndReplace(toFindC, replaceWithD, theText))

And, it returns the same class of text as the original (as a result of the “beginning” bit).


on findAndReplace(toFind, replaceWith, theText)
	set astid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to toFind
	set textItems to theText's text items
	set AppleScript's text item delimiters to replaceWith
	tell textItems to set editedText to beginning & replaceWith & rest
	set AppleScript's text item delimiters to astid
	return editedText
end findAndReplace

The trick will be to identify the characters you don’t want and their appropriate replacements. Not enough info to pursue that.

This is just a portion of a script I use to rid addresses of diacritical marks. I modified it to show you the possibilities.
Just set the _limitText to ‘yesspace or nospace etc.’. No more funky file names!
Hope this helps,

contactzero

global _limitText
--LIMIT WHAT YOU CAN NAME A FILE; REMOVE DIACRITICALS, ODDBALL CHARS
--We're going to get rid of all the funky chars in the string below:
set stringToConvert to "teST23a a 493µ48 tin g âî¢Ã§Ã‡Ã© èå åÄ ü"

set yesspace to "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_-!#$%*()+ " -- there is a space at the end.
set nospace to "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_-!#$%*()+" -- there is NO space at the end.
set upper to "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_-!#$%*()+" -- there IS a space at the end
set lower to "abcdefghijklmnopqrstuvwxyz1234567890_-!#$%*()+ " -- there IS a space at the end
-----------------------------------------------------------------------
set _limitText to upper --<<< Change this to see possible solutions; yesspace, nospace, upper,l ower, MAKE UP YOUR OWN!
-----------------------------------------------------------------------

--MAIN
if (_limitText is equal to yesspace or _limitText is equal to nospace) then
	considering case but ignoring diacriticals
		get removeDiacriticalMarks(stringToConvert, _limitText)
	end considering
else if (_limitText is equal to upper or _limitText is equal to lower) then
	ignoring diacriticals
		get removeDiacriticalMarks(stringToConvert, _limitText)
	end ignoring
else if _caseChange is equal to title then
	ignoring diacriticals
		get removeDiacriticalMarks2(stringToConvert, _limitText)
	end ignoring
end if



-----------------------------------------------------------------------

on removeDiacriticalMarks(stringToConvert, limit) -- UPPER and lower case
	set newString to ""
	repeat with i from 1 to count of characters in stringToConvert
		set _index to offset of (character i in stringToConvert) in _limitText
		if _index is not equal to 0 then -- 0=not found
			set newString to newString & character (_index) in _limitText
		else
			--set newString to newString & character i in stringToConvert
		end if
		
	end repeat
	return newString
end removeDiacriticalMarks