Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: IsTextUnicode Text Unicode String Get Check ANSI
;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfIsTextUnicode (strFilename) intBBsize = FileSize (strFilename, 1) If intBBsize == "0" Then Return @FALSE hdlBB = BinaryAlloc (intBBsize) intBytesRead = BinaryRead (hdlBB, strFilename) blnTestPassed = DllCall ("Advapi32.dll", long : "IsTextUnicode", lpbinary : hdlBB, long : intBBSize, lpnull) ;blnTestPassed = DllCall ("Unicows.dll", long : "IsTextUnicode", lpbinary : hdlBB, long : intBBSize, lpnull) hdlBB = BinaryFree (hdlBB) Return blnTestPassed ;.......................................................................................................................................... ; This Function "udfIsTextUnicode" returns a boolean value which indicates if a given file is likely to contain a form of Unicode text or not. ; ; (c)Detlev Dalitz.20030701.20100114. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ; Test. strFolderTemp = ShortCutDir ("Local Settings", 0, 1) : "Temp\" strFileAnsi = strFolderTemp : "out.ansi.txt" strFileUC = strFolderTemp : "out.uc.txt" intResult1 = RunHideWait ("cmd.exe", "/c dir /-p *.* >""" : strFileAnsi : """") intResult2 = RunHideWait ("cmd.exe", "/u /c dir /-p *.* >""" : strFileUC : """") strText1 = FileGet (strFileAnsi) strText2 = FileGet (strFileUC) strText1 = StrSub (strText1, 1, 50) strText2 = StrSub (strText2, 1, 50) blnResult1 = udfIsTextUnicode (strFileAnsi) ; 0 = @FALSE. blnResult2 = udfIsTextUnicode (strFileUC) ; 1 = @TRUE. strMsgTitle = "Test: Ansi - Unicode" strMsgText = "Ansi:" : @LF : """" : strText1 : """" : @LF : "IsUnicode: " : blnResult1 : @LF : @LF : "Unicode:" : @LF : """" : strText2 : """" : @LF : "IsUnicode: " : blnResult2 Message (strMsgTitle, strMsgText) Exit
I want to make a comment regarding IsTextUnicode API, because this function is a "try to guess" and it is not guaranteed that the result is always the correct status of the actual situation. That should be known and taken into account.
Please read:
http://blogs.msdn.com/michkap/archive/2005/01/30/363308.aspx
http://blogs.msdn.com/michkap/archive/2006/06/14/631016.aspx
http://blogs.msdn.com/michkap/archive/2006/07/11/662342.aspx
http://blogs.msdn.com/oldnewthing/archive/2007/04/17/2158334.aspx
http://blogs.msdn.com/oldnewthing/archive/2004/03/24/95235.aspx
Article ID: W18394
Filename: udfIsTextUnicode.txt
File Created: 2010:02:16:09:58:40
Last Updated: 2010:02:16:09:58:40