Digisoul Posted December 11, 2008 Share Posted December 11, 2008 (edited) Hello guys,I want to know that how can i read any opend file multiple times. i wrote some exapmles wich explane my problem more clear1st: exampleGlobal $f= FileOpen('e:\games\nfs7.exe',16); file size is 178 MB Global $data = FileRead($f) $read1 = read(987) MsgBox(0,"512",$read1) $read2= read(256) MsgBox(0,"256",$read2) Func read($bytes) Switch $bytes Case 0 Return $data Case Else Return StringMid($data,1,$bytes) EndSwitch EndFuncThis example works gr8 with small files but not work for huge file, actualy wen i run this code my prog will freez 2nd: exampleglobal $f= FileOpen('e:\games\nfs7.exe',16); file size is 178 MB $read1 = read(987) MsgBox(0,"512",$read1) $read2= read(256) MsgBox(0,"256",$read2) Func read($bytes) Switch $bytes Case 0 Return FileRead($f) Case Else Return fileread($f,$bytes) EndSwitch EndFuncThis code give me the quick result but wen i call read function for $read2 it will cut the data that i call for $read1.and never shows the data frm 1st byte.i want something like; when will i call the read function it returns the data from the 1st byte. so plz help me.thanks in advance for your kind help. Edited December 11, 2008 by Digisoul 73 108 111 118 101 65 117 116 111 105 116 Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 11, 2008 Share Posted December 11, 2008 Hello guys, I want to know that how can i read any opend file multiple times. i wrote some exapmles wich explane my problem more clear 1st: example Global $f= FileOpen('e:\games\nfs7.exe',16); file size is 178 MB Global $data = FileRead($f) $read1 = read(987) MsgBox(0,"512",$read1) $read2= read(256) MsgBox(0,"256",$read2) Func read($bytes) Switch $bytes Case 0 Return $data Case Else Return StringMid($data,1,$bytes) EndSwitch EndFunc This example works gr8 with small files but not work for huge file, actualy wen i run this code my prog will freez 2nd: example global $f= FileOpen('e:\games\nfs7.exe',16); file size is 178 MB $read1 = read(987) MsgBox(0,"512",$read1) $read2= read(256) MsgBox(0,"256",$read2) Func read($bytes) Switch $bytes Case 0 Return FileRead($f) Case Else Return fileread($f,$bytes) EndSwitch EndFunc This code give me the quick result but wen i call read function for $read2 it will cut the data that i call for $read1. and never shows the data frm 1st byte. i want something like; when will i call the read function it returns the data from the 1st byte. so plz help me. thanks in advance for your kind help. Although AutoIt allows a single variable to be up to 2GB in length, the practical limit imposed by the Win32 environment (maybe no in Win64?) limits you to more like 128MB in real use. You can read the file in parts, as each call to FileRead() increments the pointer of what gets read next. This is why your $read2 is the next data AFTER what you got in $read1. You can modify this pointer to read a specific part of the file using _WinAPI_ReadFile(). Make sure you have the latest Beta downloaded and check it out in the Beta help file. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Digisoul Posted December 12, 2008 Author Share Posted December 12, 2008 Although AutoIt allows a single variable to be up to 2GB in length, the practical limit imposed by the Win32 environment (maybe no in Win64?) limits you to more like 128MB in real use. You can read the file in parts, as each call to FileRead() increments the pointer of what gets read next. This is why your $read2 is the next data AFTER what you got in $read1. You can modify this pointer to read a specific part of the file using _WinAPI_ReadFile(). Make sure you have the latest Beta downloaded and check it out in the Beta help file. Thank you PsaltyDS. i tried with this but the result was same as that i mentioned in example 1 in my 1st post. #include <WINAPI.au3> Global $f,$sz,$bBuffer,$BufferSize = 2048 $sz = FileGetSize('e:\games\nfs7.exe') $bBuffer = DllStructCreate("byte[" & $sz & "]") $f = _WinAPI_CreateFile('e:\games\nfs7.exe', 2, 2) $read1 = read(987) MsgBox(0,"512",$read1) $read2= read(256) MsgBox(0,"Full",$read2) Func read($bytes) _WinAPI_SetFilePointer($f, 0) Switch $bytes Case 0 $read=_WinAPI_ReadFile($f, DllStructGetPtr($bBuffer), $sz, $sz) if $read <> false Then Return DllStructGetData($bBuffer, 1) Case Else $read=_WinAPI_ReadFile($f, DllStructGetPtr($bBuffer), $BufferSize, $bytes) if $read <> false Then Return DllStructGetData($bBuffer, 1) EndSwitch EndFunc Func _WinAPI_SetFilePointer($hFile, $nDistance, $nMethod = 0) Local $nRet $nRet = DllCall("kernel32.dll", "dword", "SetFilePointer", "ptr", $hFile, "long", $nDistance, "ptr", 0, "dword", $nMethod) Return $nRet[0] EndFunc please help me to improve this code 73 108 111 118 101 65 117 116 111 105 116 Link to comment Share on other sites More sharing options...
ChangMinYang Posted December 12, 2008 Share Posted December 12, 2008 Try to "MsVcrt.dll"'s fopenSearch Expression = fsetpos + fread 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