Jump to content

checking fileread access

Recommended Posts


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))

Also, doesn't this would result in reading two times the file ?

Here is the writescript :

$hFile = FileOpen($file_path, 2)
FileWrite($hFile, $Return)

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 ?



Edited by kiboost

Win7 pro x64. scripts compiled to x64. - Autoit v3.3.6.1 | Scite 1.79

Link to post
Share on other sites

Thanks Tvern,

The problem is with that :

While @error <> 1

$report = FileRead($K_reportfile)


The mainscript doesn't work at all, like the while loop is infinite

same with that :

While @error <> -1

$report = FileRead($K_reportfile)


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 post
Share on other sites

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!")

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 post
Share on other sites

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...