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.
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?

miauu's picture

Try this function:

-- function to make a filename valid by replacing illegal characters with a '_'
		function MakeFileNameValid fileName = -- fname must be just filename, no path....
		(
			local illegal_characters =":/\\[email protected]#$%^&*()+=|'?><;[]{}\"" -- illegal characters in file name
			local res = copy fileName
 
			-- make sure the object name is legal for a filename
			local count = res.count
			for i = 1 to count do
			(
				if (findString illegal_characters res[i]) != undefined do -- replace illegal characters with _
					res[i] = "_"
			)
			--
			res
		)
artrender.info's picture

I've found smth like this for php and javascript

php

if (preg_match('/[^\x30-\x7F]/', $_POST['full_name']) > 0)
{
    $error = true;
}

x30 will exclude: !"#$%&'()*+,-./.

java

var foreignCharacters = $("#foreign_characters").val();
var rforeign = /[^\u0000-\u007f]/;
 
if (rforeign.test(foreignCharacters)) {
  alert("This is non-Latin Characters");
} else {
  alert("This is Latin Characters");    
}

how to implement these things in maxscript:

for m in getClassInstances BitmapTexture where (foreignfn m.filename == true) do
 
rename m.filename

For the other hand we have:

character.set parameter for maxscript! I'm still confused!!!

Comment viewing options

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