Jump to content

Recommended Posts

Posted (edited)

Hello guys,

Im in great problem write now, I want to know that how can i read file From EOF to Bigening Of File.

here is my code

#include <WinApi.au3>
Global $nBytes

$hFile = _WinAPI_CreateFile("C:\Documents and Settings\Adeel\Desktop\test.txt", 2, 2, 2)
$sz = FileGetSize("C:\Documents and Settings\Adeel\Desktop\test.txt")
MsgBox(0,"",$sz)

$r = 10

_WinAPI_SetFilePointer($hFile,-10,2)
While 1

$ret_sig = read($hFile, 10)

MsgBox(0,"",StringReplace(BinaryToString($ret_sig)," ","_"))

$r += 10

if $r > $sz Then ExitLoop

WEnd

Func read($hFile, $bytes)
    $tBuffer = DllStructCreate("byte[" & $bytes & "]")
    $read = _WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), $bytes, $nBytes)
    If $read <> False Then
        Return DllStructGetData($tBuffer, 1)
    Else
        Return $read
    EndIf
EndFunc ;==>read

I want to read reversely 10 bytes of file.

Thanks in Advance for your help.

Edited by Digisoul

73 108 111 118 101 65 117 116 111 105 116

Posted

Use a loop utilizing the following functions:

FileGetSize()

_WinAPI_ReadFile()

_WinAPI_SetFilePointer()

Do you plz define this ?

coz i m already using these function in LOOP?

73 108 111 118 101 65 117 116 111 105 116

Posted (edited)

Something like

#include <winapi.au3>
local $nBytes, $tBuffer_save
$filename = @ScriptDir & '\test.txt'
$BytesRead = FileGetSize($filename)

$hFile = _WinAPI_CreateFile($filename, 2, 2)
while $BytesRead > 10
    $BytesRead -= 10
    $tBuffer = DllStructCreate("byte[10]")
    _WinAPI_SetFilePointer($hFile, $BytesRead)
    _WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), 10, $nBytes)
    $tBuffer_save &= BinaryToString(DllStructGetData($tBuffer, 1))
WEnd

$tBuffer = DllStructCreate("byte[" & $BytesRead & "]")
_WinAPI_SetFilePointer($hFile, 0)
_WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), $BytesRead, $nBytes)
$tBuffer_save &= BinaryToString(DllStructGetData($tBuffer, 1))

MsgBox(0,'',$tBuffer_save)
Edited by KaFu
Posted

Something like

#include <winapi.au3>
local $nBytes, $tBuffer_save
$filename = @ScriptDir & '\test.txt'
$BytesRead = FileGetSize($filename)

$hFile = _WinAPI_CreateFile($filename, 2, 2)
while $BytesRead > 10
    $BytesRead -= 10
    $tBuffer = DllStructCreate("byte[10]")
    _WinAPI_SetFilePointer($hFile, $BytesRead)
    _WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), 10, $nBytes)
    $tBuffer_save &= BinaryToString(DllStructGetData($tBuffer, 1))
WEnd

$tBuffer = DllStructCreate("byte[" & $BytesRead & "]")
_WinAPI_SetFilePointer($hFile, 0)
_WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), $BytesRead, $nBytes)
$tBuffer_save &= BinaryToString(DllStructGetData($tBuffer, 1))

MsgBox(0,'',$tBuffer_save)
Thank you very much Mate thats work for me.

73 108 111 118 101 65 117 116 111 105 116

Posted

Something like

#include <winapi.au3>
local $nBytes, $tBuffer_save
$filename = @ScriptDir & '\test.txt'
$BytesRead = FileGetSize($filename)

$hFile = _WinAPI_CreateFile($filename, 2, 2)
while $BytesRead > 10
    $BytesRead -= 10
    $tBuffer = DllStructCreate("byte[10]")
    _WinAPI_SetFilePointer($hFile, $BytesRead)
    _WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), 10, $nBytes)
    $tBuffer_save &= BinaryToString(DllStructGetData($tBuffer, 1))
WEnd

$tBuffer = DllStructCreate("byte[" & $BytesRead & "]")
_WinAPI_SetFilePointer($hFile, 0)
_WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), $BytesRead, $nBytes)
$tBuffer_save &= BinaryToString(DllStructGetData($tBuffer, 1))

MsgBox(0,'',$tBuffer_save)

I tried to ristrict to read 1MB from EOF if the file is Greater then 1MB ?

how can i complete this task ?

73 108 111 118 101 65 117 116 111 105 116

Posted

#include <winapi.au3>
local $nBytes, $tBuffer_save
$filename = @ScriptDir & '\test.txt'
$FileSize = FileGetSize($filename)
$BytesToRead = 1024 * 1024
$BytesToRead_Step = 10
$BytesToRead_Org = $BytesToRead

$hFile = _WinAPI_CreateFile($filename, 2, 2)
while $BytesToRead > 10
    $BytesToRead -= 10
    $tBuffer = DllStructCreate("byte[" & $BytesToRead_Step & "]")
    _WinAPI_SetFilePointer($hFile, $FileSize - ($BytesToRead_Org - $BytesToRead))
    _WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), 10, $nBytes)
    $tBuffer_save &= BinaryToString(DllStructGetData($tBuffer, 1))
WEnd

$tBuffer = DllStructCreate("byte[" & $BytesToRead & "]")
_WinAPI_SetFilePointer($hFile, 0)
_WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), $BytesToRead, $nBytes)
$tBuffer_save &= BinaryToString(DllStructGetData($tBuffer, 1))

MsgBox(0,'',$tBuffer_save)

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
  • Recently Browsing   0 members

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