I have not done anything with these suggestions as yet. Was fighting politics and other junk today. To clear up the assumptions, although not appending the file, I am writing to it by virtue of a name change and move.
The process is: check for the existance of the file. If it exists (using Binary stream) I increment a counter, and wait for a couple of seconds. I check again and repeat.
Dim f As FolderItem
f = GetFolderItem(GatePath + App.ManageFileTransfer.InterfaceFileName)
Dim bs As BinaryStream
Dim IntCmdFile As String
If f<> Nil and f.Exists then
bs = BinaryStream.Open(f, False)
if bs = nil then
bs.close
Return False
Else
On the 4 check, I rename the file adding date and time to the name, and move it to a different folder. Renaming and moving it allows another to be created while I am doing my bit. Following the rename/move, I read it and do the work etc.
I have seen in the past where the file exists both in the original location, and the new location (with the rename). Maybe due to using False in the .open command?
Yes, after reviewing this for the first time in 2 years, I see that. I think there was a reason for it, none that really seem valid now however. If another has it open and locked, and I open it as locked, then I get the error. Seems like a good check point. Much better than the nothing I have now.
This app was thrown together over a weekend 2 years ago. I had no idea how much it would be used. Guess it is time to go back, clean it up and improve it.
Thanks again to all for your feedback and contribiutions to this thread! I had no idea it would be so popular!
[quote=206665:@Tim Seyfarth]My app is written in Xojo.
Tim[/quote]
I wrote: I assume the other app the one writing the temporary file you are to open is not written in Xojo.
I have no idea what it is written in. Further, for this type of use, the ‘other’ may be provided a several different ‘others’. Installation by installation of course.
Bottom line, I have no way to tell what tools they have used to write their app with. Obviously you think this is important. May I ask why? What is your line of thinking in the matter?
Thanks Eli and have a wonderful day in Berlin!
Tim
That’s what I meant: you can not rely on knowing how the other app opens the file while writing it, with denying others to read it, or not.
Hence my suggestion to go a level deeper and to use declares to get notified by the OS when the file state changes ( > created > opened > closed > deleted).
I rarely do declare stuff on Windows (OS X is my playground). But I assume it would be declares into: Directory Management Functions
Maybe these C functions:
FindFirstChangeNotification: Creates a change notification handle and sets up initial change notification filter conditions.
FindNextChangeNotification: Requests that the operating system signal a change notification handle the next time it detects an appropriate change.
I’m sure one of the Windows pros in this forum has much better knowledge than me on how to monitor file system changes.