Jump to content

_FileCountLines only for ANSI ?


Recommended Posts

  • Moderators

does _FileCountLines work only for ANSI format files ? It's giving negative values for Plaintext files in unicode format(English only). ANyway to convert the file to ANSI in AutoIt before _FileCountLines ?

What version of AutoIt are you using? I thought we could do what your asking in the latest betas with the FileRead() that _FileCountLines() uses.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

What version of AutoIt are you using? I thought we could do what your asking in the latest betas with the FileRead() that _FileCountLines() uses.

I tried it with 3.2.0.1 and 3.2.1.12. Both return negative numbers.

@dragonlord

You will have to convert the Unicode Strings to ANSI/ASC. You can use the functions provided in the following link. http://www.autoitscript.com/forum/index.php?showtopic=21815. However, then you can't use _FileCountLines() anymore. You will have to implement that by yourself. Alternatively, use an external tool to convert the file to ANSI.

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

  • Moderators

I tried it with 3.2.0.1 and 3.2.1.12. Both return negative numbers.

@dragonlord

You will have to convert the Unicode Strings to ANSI/ASC. You can use the functions provided in the following link. http://www.autoitscript.com/forum/index.php?showtopic=21815. However, then you can't use _FileCountLines() anymore. You will have to implement that by yourself. Alternatively, use an external tool to convert the file to ANSI.

Cheers

Kurt

Hmmm, if you want another option to just output the file to another location other then what Kurt gave you, you could try this:
Dim $hInFile = @HomeDrive & '\Unicode.txt', $hOutFile = @HomeDrive & '\Ansi.txt'
Run(@ComSpec & ' /c Type "' & $hInFile & '" > "' & $hOutFile & '"', '', @SW_HIDE)
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • 1 month later...

does _FileCountLines work only for ANSI format files ? It's giving negative values for Plaintext files in unicode format(English only). ANyway to convert the file to ANSI in AutoIt before _FileCountLines ?

it is my edition for unicode files:
Func _FileUnicodeCountLines ($sFilePath)
    Local $N = FileGetSize($sFilePath) - 2
    If @error Or $N <0 Then Return 0
    Local $F = _WCStrToString (FileRead ($sFilePath, $N))
    Return StringLen (StringAddCR ($F)) - StringLen ($F) + 1
EndFunc

Func _WCStrToString ($wcString)
    Local $sizeIn= StringLen ($wcString), $sizeOut = BitShift ($sizeIn, 1)
    If $sizeIn =0 Then Return ''
    Local $bufOut= DllStructCreate ("char[" & $sizeOut & "]")
    Local $bufIn = DllStructCreate ("byte[" & $sizeIn  & "]")
    Local $ptrIn = DllStructGetPtr ($bufIn)
    DllStructSetData ($bufIn, 1, $wcString)
    If DllStructGetData ($bufIn, 1, 1) =-1 AND DllStructGetData ($bufIn, 1, 2) =-2 Then
        $ptrIn   +=2
        $sizeOut -=1
    EndIf
    Local $ret = DllCall ("Kernel32.dll", "int", "WideCharToMultiByte", _
        "int", 0, _
        "int", 0, _
        "ptr", $ptrIn, _
        "int", $sizeOut, _
        "ptr", DllStructGetPtr ($bufOut), _
        "int", $sizeOut, _
        "int", 0, _
        "int", 0 )   
    If $ret [0] Then
        Return DllStructGetData ($bufOut, 1)
    Else
        $ret = DllCall ("Kernel32.dll", "int", "GetLastError")
        SetError ($ret [0])
    EndIf
EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...