473,231 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

Is there a standard way to check whether or not a file is in use?

Try to do something with it, and look at the exception? Some other
way?

Thanks!
Apr 11 '08 #1
3 1437
On Fri, 11 Apr 2008 10:48:49 -0700, sherifffruitfly
<sh*************@gmail.comwrote:
Try to do something with it, and look at the exception? Some other
way?
It depends on why you want to know. If you're trying to find out whether
it's in use because you yourself want to use it, then yes...the best,
"standard" way is to simply attempt the operation and see if that
operation succeeds.

If you want to simply inspect the state without affecting the file, I
don't think that's possible from within .NET. However, there are
lower-level OS mechanisms that you could use. This isn't an appropriate
forum for learning about them though. You'd be better off in a newsgroup
specific to unmanaged Win32 programming.

Pete
Apr 11 '08 #2
On Apr 11, 11:04 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Fri, 11 Apr 2008 10:48:49 -0700, sherifffruitfly

<sherifffruit...@gmail.comwrote:
Try to do something with it, and look at the exception? Some other
way?

It depends on why you want to know. If you're trying to find out whether
it's in use because you yourself want to use it, then yes...the best,
"standard" way is to simply attempt the operation and see if that
operation succeeds.
Good enough - I just typically shy away from "exception-based
programming", so I thought I'd see if there were another common way.
Thanks a bunch!
Apr 11 '08 #3
On Fri, 11 Apr 2008 11:16:49 -0700, sherifffruitfly
<sh*************@gmail.comwrote:
Good enough - I just typically shy away from "exception-based
programming", so I thought I'd see if there were another common way.
Not that I know of. Exceptions are expensive, granted. But so is file
i/o. :)

In any case, logically if you are going to need access to the file anyway,
it doesn't do you any good to check the file's status beforehand, since
the status could change between the time you check and the time you try to
use the file.

Even if the file's accessible, it might not be by the time you try to use
it. And even in the situation where checking first could theoretically
save you the cost of the exception, now you've got the potential for a
false negative; that is, the check could fail even though by the time you
try to use the file, you could have succeeded.

Pete
Apr 11 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Marko Faldix | last post by:
Hello, with Python 2.3 I can write umlauts (a,o,u umlaut) to a file with this piece of code: import codecs f = codecs.open("klotentest.txt", "w", "latin-1") print >>f, unicode("My umlauts...
2
by: bruce varley | last post by:
Hello, I suspect a platform bug, but first I'd like to check whether the C++ standard library has changed the handling of streams in a way that creates the behaviour I'm observing. Hence this...
2
by: Peng Yu | last post by:
Put #include <complex.h> in my source code. However, it seems that the included file isn't compatible with C99. I suspect that C99 GCC is not local machine. Is there any compiler tag to help me...
43
by: Steven T. Hatton | last post by:
Now that I have a better grasp of the scope and capabilities of the C++ Standard Library, I understand that products such as Qt actually provide much of the same functionality through their own...
31
by: Bill Cunningham | last post by:
There must be some change in the standard because I ran into this error when I put this line in a header. # pragma once I only wanted the headers to be included once. The compiler said something...
7
by: andylcx | last post by:
Hi all: The c++ language can check whether the file exist or not. I am wondering how c language does this job? Thanks a lot! Andy
5
by: funkyj | last post by:
I love pexpect because it means I may never have to use expect again (I don't do any heavy expect lifting -- I just need simple tty control)! As a python advocate I find it embarassing how...
270
by: jacob navia | last post by:
In my "Happy Christmas" message, I proposed a function to read a file into a RAM buffer and return that buffer or NULL if the file doesn't exist or some other error is found. It is interesting...
126
by: Dann Corbit | last post by:
Rather than create a new way of doing things: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html why not just pick up ACE into the existing standard:...
4
by: sherifffruitfly | last post by:
Try to do something with it, and look at the exception? Some other way? Thanks!
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.