Guest Posted February 7, 2014 Share Posted February 7, 2014 (edited) Hello, I nead help. this command: FileRead("database.txt",1000) can read the first 1000 characters of the file. but i need to read the only last 1000 characters and i don't see this option in the function. i know that i can read the whole file and then use StringRight($fileread,1000) but in this way the script will load a lot of unnecessary data to the memory so it will take more memory and it also will take more time to read the file.. i need to read directly the last 1000 characters.. how can i do this? thanks for helpers! Edited February 7, 2014 by Guest Link to comment Share on other sites More sharing options...
nullschritt Posted February 7, 2014 Share Posted February 7, 2014 I think there is a way to do this using winapi functions. You cannot achieve this result with the normal fileread function. Link to comment Share on other sites More sharing options...
Solution jdelaney Posted February 7, 2014 Solution Share Posted February 7, 2014 (edited) try this: $hFile = FileOpen("file.txt") FileSetPos($hFile,-1000,$FILE_END) $string = FileRead($hFile,1000) ConsoleWrite(StringLen($string) & " " & $string & @CRLF) I created a dummy file, with multi thousands of chars...all asdf...at the end, i put in string=last the above outputs last (as the last chars) and count of 1000 Edited February 7, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Guest Posted February 7, 2014 Share Posted February 7, 2014 (edited) I think there is a way to do this using winapi functions. You cannot achieve this result with the normal fileread function. Where?I looked in the UDF and I have not found. try this: $hFile = FileOpen("file.txt") FileSetPos($hFile,-1000,$FILE_END) $string = FileRead($hFile,1000) ConsoleWrite(StringLen($string) & " " & $string & @CRLF) From looking at your code, it does not matter what you do later ..At first you read the whole file with FileOpen("file.txt") and that's exactly what I do not want to do. EDIT: Oops, I did not see properly before.I'll check your code Edited February 7, 2014 by Guest Link to comment Share on other sites More sharing options...
jdelaney Posted February 7, 2014 Share Posted February 7, 2014 Well, it cuts out the memory usage to hold all that data from your FileRead string, at least. The string from mine will limit to only 1k chars. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
jchd Posted February 7, 2014 Share Posted February 7, 2014 Gil900, FileOpen doesn't read he file! This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Guest Posted February 7, 2014 Share Posted February 7, 2014 (edited) Gil900, FileOpen doesn't read he file! I know.I edited my response.I just didn't saw good .. (I thought I saw FileRead instead FileOpen)jdelaney, thank you.I checked your code and it does exactly what I want and it works!Thanks Edited February 7, 2014 by Guest Link to comment Share on other sites More sharing options...
nullschritt Posted February 8, 2014 Share Posted February 8, 2014 try this: $hFile = FileOpen("file.txt") FileSetPos($hFile,-1000,$FILE_END) $string = FileRead($hFile,1000) ConsoleWrite(StringLen($string) & " " & $string & @CRLF) I created a dummy file, with multi thousands of chars...all asdf...at the end, i put in string=last the above outputs last (as the last chars) and count of 1000 Oh, well, I guess I didn't know what I was talking about in this case. Never seen the filesetpos() function used before. 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