How close DOS files? (OpenInsight Specific)
At 03 DEC 1999 08:11:53AM Oystein Reigem wrote:
If I write a DOS file from my app (with OSBWrite) and afterwards open it with Word, I get a warning the file is in use by a different user. How can I let my app really let go of the file? I do a OSClose, but that doesn't seem to be enough. Should it?
- Oystein -
At 03 DEC 1999 09:06AM Don Bakke wrote:
Oystein,
AFAIK doing an OSClose should be enough.
At 03 DEC 1999 10:06AM Oystein Reigem wrote:
Don,
Would you be so kind and check if the rest is OK? Perhaps there's something dodgy with the way I create the file.
- Oystein -
/* delete the file if it already exists */ OSOpen OutputFileName to OutputFileHandle then OSClose OutputFileHandle OSDelete OutputFileName end /* create the file */ OSWrite "" to OutputFileName /* create file handle */ OSOpen OutputFileName to OutputFileHandle else ...error handling... end /* init write */ OutputFilePos=0 ... ... ... Line=... : CrLf /* write line to file */ OSBWrite Line on OutputFileHandle at OutputFilePos if Status() 0 then ...error handling... end else OutputFilePos += len(Line) end ... ... ... /* close file */ OSClose OutputFileHandle
At 03 DEC 1999 10:14AM Don Miller - C3 Inc. wrote:
Oystein ..
A couple of possibilities:
1. The file is non-sharable or there are some ownership issues regarding access by another user that cause the file to be opened in read-only mode.
2. If you are using Netware, check the file's properties by doing FLAG . This will list both the DOS and Netware attributes for the file.
A possible solution would be not to delete the file but to simply clear its contents (OSWRITE "" on FILE_HANDLE if it exists). In this way, the ownership and rights would not be changed assuming that it was created properly in the first place (Sharable / Read-Write, etc.)
Just a thought ..
Don Miller
C3 Inc.
At 03 DEC 1999 12:32PM Don Bakke wrote:
Oystein,
I don't know if this will resolve your problem, but here are a couple of thoughts I had from looking at your code:
<code> /* delete the file if it already exists */ OSOpen OutputFileName to OutputFileHandle then OSClose OutputFileHandle OSDelete OutputFileName end </code>
This seems redundant, especially since you are OSWriting a null to the file in the next line.
<code> /* create the file */ OSWrite "" to OutputFileName /* create file handle */ OSOpen OutputFileName to OutputFileHandle else …error handling… end </code>
Shouldn't the above be reversed? You are OSWriting before your OSOpen. Because of this, one of your OSCloses might not be working correctly.
At 03 DEC 1999 02:26PM Don Miller - C3 Inc. wrote:
Oystein ..
Don has sharp eyes.
Don Miller
C3 Inc.
At 04 DEC 1999 06:34AM Steve Smith wrote:
What you are seeing is probably (a) what Don Bakke identified and (b) that you should perform a FLUSH after each OS I/O group of statements.
Steve
At 06 DEC 1999 05:34AM Oystein Reigem wrote:
Steve/Don/Don,
Admit my code looks like two functions crashed and merged and got their lines rearranged. Sort of Basic+ scar tissue. It's a long story.
I reverted to the code in the OSWrite online help, but without success:
OSOpen "OSTEST" To file_var Else
Create an operating system file.OSWrite "" To "OSTEST"
Create the necessary file handle.OSOpen "OSTEST" To file_var Else* error handlingEndEnd
Then I added a Flush statement before my OSClose and the problem went away. Thanks, Steve! But why exactly does Flush help?
- Oystein -
At 06 DEC 1999 06:43AM Steve Smith wrote:
Oystein - Lucky guess.
A FLUSH is designed to put all the buffered stuff to disk. Some is buffered by the network itself and some by the BFS itself. And it would have to close the files to get the buffer contents to disk.
So any caching that's happening would in part be resolved by a flush, otherwise you may be operating on an open file, or trying to share a handle (=error material)
Steve
At 06 DEC 1999 07:07AM Oystein Reigem wrote:
Steve,
I still don't understand why OSClose cannot finish the file properly. But thanks again!
- Oystein -
At 06 DEC 1999 07:19AM Oystein Reigem wrote:
Don,
]]/* delete the file if it already exists */
]]OSOpen OutputFileName to OutputFileHandle then
]]OSClose OutputFileHandle
]]OSDelete OutputFileName
]]end
]This seems redundant, especially since you are
]OSWriting a null to the file in the next line.
Now I remember why I did it - to clear the file. Else if I write to an existing file, and the new content is shorter than the old, I get old data at the end. So what is the proper way to clear an existing file, or to set a new EOF?
- Oystein -
At 06 DEC 1999 09:27AM Don Bakke wrote:
Oystein,
I could be wrong but OSWriting a null should clear the file. OSBWriting a null will only clear the byte you are pointing to.
If this is not the case then there are a few routines I need to double check .
At 06 DEC 1999 10:32AM Oystein Reigem wrote:
Don,
You're right about OSWrite "". I always used OSWrite, but I've had a case were it wasn't executed. I also discovered another thing that must have confused me earlier. Final (?) version:
/* try to open the output file */
OSOpen FileName to FileVar then
/* the file exists. clear it */OSWrite "" to FileNameend else
/* the file does not exist. create it */OSWrite "" to FileName/* open the file */OSOpen FileName to FileVar then...error handling...endend
(Btw - I said in a different post I quoted the help text on OSWrite. It's actually in the help for OSBRead.)
- Oystein -