|
|
Detecting if a file is open
{ Looks more like an OS question, but let's see if we can elicit
some C++ discussion out of it. -mod }
Hi Everyone,
I'm trying to detect if an excel file is open (not if it exists but is
actually opened by the user). One approach that worked is before
generating the file, I check if it exists and if it does, I try
deleting it. If it allows for the file to be deleted, then it is not
open.
The problem with this approach is that the file is deleted (in the
event that it is not open). I also tried creating an ofstream handle
and associated it with the excel file. Unfortunately, this association
automatically causes the file to be opened. So the is_open() call
always returns true even if the file has not been opened by the user.
Does anyone know of a more elegant of detecting if a file is open?
Thank you for your time,
Puja
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
ptmalhotra (1)
|
5/14/2009 1:48:02 AM |
|
On 14 mai, 10:48, Puja <ptmalho...@gmail.com> wrote:
> Does anyone know of a more elegant of detecting if a file is open?
When the application launches, it creates a file. When it terminates,
it deletes that file.
If the file exists, the application runs.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
Mathias
|
5/14/2009 11:48:21 AM
|
|
Puja wrote:
> { Looks more like an OS question, but let's see if we can elicit
> some C++ discussion out of it. -mod }
>
> Hi Everyone,
>
> I'm trying to detect if an excel file is open (not if it exists but is
> actually opened by the user). One approach that worked is before
> generating the file, I check if it exists and if it does, I try
> deleting it. If it allows for the file to be deleted, then it is not
> open.
>
> The problem with this approach is that the file is deleted (in the
> event that it is not open). I also tried creating an ofstream handle
> and associated it with the excel file. Unfortunately, this association
> automatically causes the file to be opened. So the is_open() call
> always returns true even if the file has not been opened by the user.
>
> Does anyone know of a more elegant of detecting if a file is open?
>
As far I'm aware neither the iostream lib nor fopen and friends provides
for the notion that a file on disk is opened by another process/user.
The best thing you can do IMHO is to use the Win32 file functions to
determine the state of the file.
On the other hand, what is the problem you are trying to solve? Do you
really need to know if it's open, or just need to know if you should
write to it?
br,
Martin
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
Martin
|
5/14/2009 12:13:29 PM
|
|
|
2 Replies
207 Views
(page loaded in 0.075 seconds)
Similiar Articles: check file is open or not - comp.soft-sys.matlabDetect if CSS file was loaded - comp.lang.javascript Check if a file is open or not - comp.lang.java.help Detect if CSS file was loaded - comp.lang.javascript check file ... detecting corrupted jpeg files - comp.compressionBut I was thinking of using a program like HTTRACK to download files in combination with a command-line utility to detect errors in jpg files. Perhaps the log file of ... Xilinx Encrypted bit file - comp.arch.fpgaI know Xilinx keeps its bit file header format secret. But, does anyone know how to detect if a bit file is encrypted or not? As part of our manufac... Detect end-of-file of Binary file - comp.unix.programmer ...Hi All, I want to transfer the binary file over the network using tcp socket. In this how could I detect the end-of-file at the receiving end for clo... Detecting when the garage door opens or is left opened - comp.home ...X10 device to detect open circuit or voltage drop - comp.home ... Detecting when the garage door opens or is left opened - comp.home ... X10 device to detect open circuit ... Accessing file while it is being copied - comp.lang.java ...In order to lock a file, you have to open it first, and I get a FileNotFoundException when I ... Somehow, I need to be able to detect when the copy >>> process has completed ... Detect interface failure. - comp.unix.programmerI open a RAW socket on IP1. Sometime later, I have disabled A1 . But when ... ... Well, what I want to know is, if I can use something like Routing sockets to detect my ... Check if a file is open or not - comp.lang.java.helphi, I want to check if a file is open or not using Java. I want to know if the file is accessed by some other program while i m opening it though java... CSS: "tagname.classname" or ".classname" - comp.lang.javascript ...Hi, Sorry if this is OT :( I have some old CSS files that have all class names preceded with tagname, like "TD.verysmall" or "span.important". I'm e... MCR detection on Windows XP - comp.soft-sys.matlabIs there a particular registry key or file or something that you can search for to detect if a particular version of the MCR is already installed on... detect if a file is open - C#(C Sharp) - TechTalkz.com Technology ...I'm using FileSystemWatcher to watch the new file creation. When there is one, I want to open it and read it's content. But, by the time when I got Detecting if a file is already open .NET FrameworkHi Is there a solid method for testing if a file is already open so I dont try an open a file in use by another process TIA? 7/23/2012 10:35:23 PM
|
|
|
|
|
|
|
|
|