473,396 Members | 1,968 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,396 software developers and data experts.

file in use by another program

Hello everyone,
is there a way to check if a file is in use by another program. One
possibility would be to poll the file for an exclusive lock, but this has
very bad consequences for the performance of my program.

Thanks, Holger
Nov 16 '05 #1
2 1571
Ive seen this discussed before and the usual answer is for your application
simply catch (and handle) any exceptions caused by file access -since there
might be other reasons why a file does not open (e.g. permissions). Simply
doing any pre-checks on the file is still no guarantee that a file is going
to open at the exact moment of the request -so you would still need to catch
and handle potential exceptions anyway.

--
Best Regards,

Mark

Mark Broadbent

mcad,mcdba,mcse+i
emailto: newsgroupsATmettayyaDOTgotadslDOTcoDOTuk
remove AT with '@' and DOT with '.' -please do not send spam or address will
be changed!
"Holger" <Ho****@discussions.microsoft.com> wrote in message
news:78**********************************@microsof t.com...
Hello everyone,
is there a way to check if a file is in use by another program. One
possibility would be to poll the file for an exclusive lock, but this has
very bad consequences for the performance of my program.

Thanks, Holger

Nov 16 '05 #2
Holger,

Before you want to use the file, you could try and access the file
through a call to the CreateFile API function. It will be more specific
with it's return value in indicating whether or not it is in use by someone
else.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Holger" <Ho****@discussions.microsoft.com> wrote in message
news:78**********************************@microsof t.com...
Hello everyone,
is there a way to check if a file is in use by another program. One
possibility would be to poll the file for an exclusive lock, but this has
very bad consequences for the performance of my program.

Thanks, Holger

Nov 16 '05 #3

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

Similar topics

1
by: freehomesp | last post by:
1 #include <sys/types.h> 2 #include <sys/times.h> 3 int 4 main(int argc,char* argv) 5 { 6 struct tms before, after; 7 8 times(&before); 9 10 pid_t pid;
18
by: utab | last post by:
Dear all, I am making a system call to the well known Gnuplot with system("gnuplot"); gnuplot opens if I only supply this command but I would like to pipe that command line in my C++...
1
by: Stuart Moore | last post by:
I've tried searching for the following, but I've had no luck. I want to execute another program from within my C++ program, and read it's stdout in a similar way to reading from a file. I do not...
1
by: Netaro | last post by:
Well... So, i have a program. A normal program, which does something, and so.. and i have another program, which wants to run the first program.... So, there are 2 questions about that problem...
8
by: Gordon Airporte | last post by:
I'm trying to find a way to take a file that another program has opened and writes to periodically, open it simultaneously in Python, and automatically update some of my objects in Python when the...
3
by: chenhong | last post by:
If it's possible, can the program run under another credential? TIA
0
by: dj | last post by:
Hello All, First, Is there a python library, method or module that will tell you if a file has been opened by another program (i.e: Word, PowerPoint, IE etc.), the methods I have found in the...
4
by: maximus tee | last post by:
hi all, i wrote a simple GUI with 2 buttons. Button1 is to launch another program. Button2 is to run test. When I click Button1, it will launch another program. After launching the program, my...
3
by: Holly Holly | last post by:
Hello there! :) I´m quite new to this here! And am now standing in front of a 'situation' :) and wanting to solve it!! :) So, is my question now, if you could help! :) I am wanting to start...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.