Forum Discussion

SchmittyT9's avatar
SchmittyT9
New Contributor
8 years ago

aqFile.Exists(filePath) is returning true, but aqFile.GetSize(filePath) returns an error

I have some code that first checks if the file exists, and then does some other stuff, including getting the file size.

If aqFile.Exists(filePath) Then
   fileSize = aqFile.GetSize(filePath)
   ' Do some other stuff
End If

This works consistently on my Windows 10 tests, but fails every time on the second line on Windows 7 with this error message: "Unable to open the file."

I'm not sure what to do here, I thought the whole point of doing the If Then statement with aqFile.Exists was to avoid this kind of error?

 

Can anyone help me out?

2 Replies

  • S_Leonardo's avatar
    S_Leonardo
    Occasional Contributor

    Are you sure that the error message refers to the second line ? 

     

    "Unable do open" is more like the user do not have permission or the file is open on another process.

  • SchmittyT9's avatar
    SchmittyT9
    New Contributor

    Yep it definitely refers to the second line.

     

    For context, the code is looping and printing out the size of the file as it is being created, so the size is progressively getting bigger, then the loop exits when the file size has stopped increasing.
    It's possibly what you said, the file is in use when the size is checked... seems to be an issue for Windows 7 though but not on Windows 10...

    Would there be a better alternative to wait for when a file has finished being created?