Dim As String pathim
Dim As Integer length1, length2
' check if file is ready
Do
length1 = Filelen(pathim)
Sleep 100
length2 = Filelen(pathim)
Loop Until length1 = length2
It works, however, the "sleeping" time is quite arbitrary, so maybe there is a better way?
#Include "windows.bi"
Dim As HANDLE fh
Dim As String filename = "c:\testfile.txt"
Do
fh = CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL)
If fh = INVALID_HANDLE_VALUE Then
Print "File doesn't exist or is used by an other process"
Else
Print "File is free to be accessed"
EndIf
CloseHandle(fh)
Sleep 1000
fh = 0
Loop Until InKey = " "
Try to create / access / delete the file while running this snippet.
There is another method, based more on messaging, which I've used in similar scenario.
This let's the external process deal with the file, as long as it takes. After finishing, it
simply creates a second, empty "message-file" that tells your program that the other
process is finished (your process can simply delete it, when it is done).
The other process is thereafter also informed, that you are "done" (file deleted).
A bit more complex but, it sort of works: both ways.
The check in your program is therefore simplified to a: FileExists("message-file") call.
@grindstone
This is very nice solution but I would rather avoid windows.bi, therefore
I will follow MrSwiss suggestion. In fact, I have contemplated something similar
with renaming of a "control" file.
Thank you both.