kiboost Posted October 21, 2010 Share Posted October 21, 2010 (edited) Hi, I have some machines that write some txt file (writescript), and then my mainscript read these txt files. Writing these txt files is very fast, but sometimes, the txt file is not readable so my mainscript doesn't work So I would like to be sure the file is read before continuing. Here what I'm trying to do in my mainscript, but doesn't work : While @error <> 1 $report = FileRead($K_reportfile, FileGetSize($K_reportfile)) WEnd Also, doesn't this would result in reading two times the file ? Here is the writescript : $hFile = FileOpen($file_path, 2) FileWrite($hFile, $Return) FileClose($hFile) If anyone could check if there is no error in writescript (not allways sure about closing file or not, handle or not), and a solution for mainscript ? Cheers, Kib Edited October 21, 2010 by kiboost Win7 pro x64. scripts compiled to x64. - Autoit v3.3.6.1 | Scite 1.79 Link to comment Share on other sites More sharing options...
Tvern Posted October 21, 2010 Share Posted October 21, 2010 In the first snippet you can remove the second FileRead parameter. It reads the entire file by default. The second snippet looks ok. If the file is locked I don't think these snippets are to blame. Link to comment Share on other sites More sharing options...
kiboost Posted October 21, 2010 Author Share Posted October 21, 2010 Thanks Tvern, The problem is with that : While @error <> 1 $report = FileRead($K_reportfile) WEnd The mainscript doesn't work at all, like the while loop is infinite same with that : While @error <> -1 $report = FileRead($K_reportfile) WEnd What I need is to be sure it read the file, before continuing the script. So, I guess, "try to read file while it is read", but doesn't translate well. Win7 pro x64. scripts compiled to x64. - Autoit v3.3.6.1 | Scite 1.79 Link to comment Share on other sites More sharing options...
Tvern Posted October 21, 2010 Share Posted October 21, 2010 Ah wait I didn't look close enough. Allot of that going on lately. Your setup in the first snippet will only exit the loop if an error occurs with FileGetSize. Try something like this: For $i = 0 To 9 $report = FileRead($K_reportfile) If $report Then ExitLoop If $i = 9 Then MsgBox(0,"Error","Filereading failed!") Sleep(1000) Next This will try to read the file 10 times in 9 seconds, continue when it succeeds, or display a warning if after 9 seconds it still fails. Link to comment Share on other sites More sharing options...
kiboost Posted October 21, 2010 Author Share Posted October 21, 2010 Many thanks !! problem solved :-))))) Win7 pro x64. scripts compiled to x64. - Autoit v3.3.6.1 | Scite 1.79 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