Page 1 of 1
Open a locked file
Posted: Thu Aug 07, 2003 10:35 pm
by RJP Computing
How can I open a locked file? I know that it will have to be read-only but I really have a use for this.
Thanks
Re: Open a locked file
Posted: Fri Aug 08, 2003 12:15 am
by Doobrey
RJP Computing wrote:How can I open a locked file? I know that it will have to be read-only but I really have a use for this.
You`ll only be able to open it "read only" if the app that locked the file has opened it with read sharing, if the app opened it with exclusive access then there`s nothing you can do until the file is closed..
You`ll have to use the Win32API to try and read it. I tried myself using PB`s ReadFile()..but even though the file was readable, it failed
Use OpenFile_() , if that returns OK then use ReadFile_() to access the file
Have a look in API-Guide for the parameters and structures..it`s too hot here, both my braincells have fried and I can`t remember !

Posted: Fri Aug 08, 2003 3:19 pm
by RJP Computing
Fred and others,
Is this a bug. Shouldn't I be able to open a locked file with the 'OpenFile' and 'ReadFile' commands. I think this should work. Of corse keeping in mind that the file isn't opened with exclusive access.
Posted: Fri Aug 08, 2003 3:41 pm
by gnozal
IIRC, it is possible with Powerbasic with the 'Shared' keyword : something like OPEN sFile FOR BINARY ACCESS READ SHARED AS #hFile ?
Should be possible with some of the OF_SHARE.. flags if Openfile() would accept flags ?
It also depends on how the file is locked : write, read, read+write, etc...
Posted: Sat Aug 09, 2003 5:30 am
by RJP Computing
Fred can you verify why these function won't open locked files. I need this feature bad
Thanks
Posted: Sat Aug 09, 2003 10:11 pm
by RJP Computing
I have verified that the file I am tring can be opened with notepad so the application that has it open does NOT have exclusive access to it.
Thanks