detect unicode file names and rename them!

How to DETECT non-english characters inside file names and rename them???

Please help!

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jazznazz's picture

Fixed Function that is

Fixed Function that is essentially a whitelist for a string - it srtips all characters that are not present in the latinChars string:

	latinChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
 
	function OnlyLatinChars str =
	(
		local strCnt = str.count
		if strCnt != 0 do
		(
			for i = strCnt to 1 by -1 where (findString latinChars str[i] == undefined) do
			(
				str = replace str i 1 ""
			)
		)
		str
	)
 
	newStr = OnlyLatinChars "ヒグループホールデФЦЦШЩЧЧ.Qwerty32___"

the output is "Qwerty32"

barigazy's picture

...

Two more versions ;)

-- VER#1
	fn OnlyLatinChars str = if isKindOf str string and str.count != 0 do
	(
		string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" ; value = ""
		for i = 1 to str.count where (findString string str[i] != undefined) do append value str[i]
		value
	)
 
	newStr = OnlyLatinChars "ヒグループホールデФЦЦШЩЧЧ.Qwerty32___"
 
-- VER#2	
	fn OnlyLatinChars str letters:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" = 
	(
		if isKindOf str string and str.count != 0 do
		(
			value = ""
			for i = 1 to str.count where (findString letters str[i] != undefined) do append value str[i]
			value
		)
	)
 
	newStr = OnlyLatinChars "ヒグループホールデФЦЦШЩЧЧ.Qwerty32___"

bga

dajono's picture

Unicodes file creates a

Unicodes file creates a complex error during the running program and stocking everything and also creating a really big bug. So that many helpful medium https://www.topdissertations.org/edubirdie-review/ help the developer for this purpose.

amir3dsmax's picture

can any one give me the code

can any one give me the code . i need this

miauu's picture

Glad you found the solution.

Glad you found the solution.

artrender.info's picture

THX! SOLVED

Thank you so much

amir3dsmax's picture

can you give code please . i

can you give code please . i need to rename nonlatine

artrender.info's picture

this idea is great!

what is theChars?

Except this I want first to detect if a filename contains at least a non-latin character and to display it

if m.filename conatins non-latin
then print m.filename

It is because: If I have a texture with nonlatin name (nonlatin.jpg) then after deleting nonlatin characters you could achive a file .jpg without name

or after renaming 2 textures:

"nonlatin1"001.jpg and "nonlatin2"001.jpg you could get 2 textures with the same name!

In order to detect first if the file contains nonlatin characters there is no need to control the name till the end and
it means inside "for" I should break the cicle:

	local latinChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 "
	function foreignfn fname =
	(
 
		local counter=0
		for i = fname.count to 1 by -1 where (findString latinChars fname[i] == undefined) do
			if (counter=counter+1)==1 then
				False
			else
				True
	)
 
 
	for m in getClassInstances BitmapTexture where (foreignfn m.filename == true) do
 		print m.filename

Could YOU help me to make corrections in this script PLEASE?!!!

miauu's picture

Try this

(
	local latinChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
 
	function OnlyLatinChars str =
	(
		local strCnt = str.count
		if strCnt != 0 do
		(
			for i = strCnt to 1 by -1 where (findString theChars str[i] == undefined) do
			(
				str = replace str i 1 ""
			)
		)
		str
	)
 
	newStr = OnlyLatinChars latinChars
)

You can add it in the function above.

artrender.info's picture

thx

but what if a filename has russian characters or chinese, or greek or any other? They can contain not exactly characters from this list! They could contain others as well!

Should I give allowed latin alphabet with numbers or there is other way as well?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.