Digisoul Posted January 28, 2009 Share Posted January 28, 2009 (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 January 28, 2009 by Digisoul 73 108 111 118 101 65 117 116 111 105 116 Link to comment Share on other sites More sharing options...
KaFu Posted January 28, 2009 Share Posted January 28, 2009 Use a loop utilizing the following functions: FileGetSize() _WinAPI_ReadFile() _WinAPI_SetFilePointer() OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Digisoul Posted January 28, 2009 Author Share Posted January 28, 2009 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 Link to comment Share on other sites More sharing options...
KaFu Posted January 28, 2009 Share Posted January 28, 2009 (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 January 28, 2009 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Digisoul Posted January 28, 2009 Author Share Posted January 28, 2009 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 Link to comment Share on other sites More sharing options...
Digisoul Posted January 28, 2009 Author Share Posted January 28, 2009 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 Link to comment Share on other sites More sharing options...
Digisoul Posted January 28, 2009 Author Share Posted January 28, 2009 Again, Thank You very much for your kind help KaFu. 73 108 111 118 101 65 117 116 111 105 116 Link to comment Share on other sites More sharing options...
KaFu Posted January 28, 2009 Share Posted January 28, 2009 #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) OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now