473,789 Members | 2,496 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Detecting File State

I'm looking for a way to detect if another process has a file open before a
second process tries to open it. I've looked into the FileAttr function but
I'm not sure if detecting a read-only state is sufficient. Can anyone
confirm or deny? TIA...
Nov 21 '05 #1
7 1428
> I'm looking for a way to detect if another process has a file open before
a

Make certain you know it exists, then,
Try to open the file exclusively,
an error means it is in use.
Good day,
Roger
Nov 21 '05 #2
"Roger" <ro***@pcsreven uecontrol.com> wrote:
I'm looking for a way to detect if another process has a file open
before a


Make certain you know it exists, then,
Try to open the file exclusively,
an error means it is in use.


I'm not proposing a better solution, but I'm pretty sure using error-
trapping or exception handling to test for a thoroughly possible condition
like this would not qualify as a "best practice"...

--
Michael Kellogg
Nov 21 '05 #3
Glen,

This is endless asked, however this is as long as there are the MS-dos
operating systems and its successors not possible when you don't create a
special management tool around it, as probably in Office is done.

Cor
Nov 21 '05 #4
I have to agree. I'm thinking there must be a way to test the state of the
file for this condition. I just haven't found anything yet...

"Michael Kellogg" <mk******@WEDEL IVERcc3.com> wrote in message
news:Xn******** *************** ***********@207 .46.248.16...
"Roger" <ro***@pcsreven uecontrol.com> wrote:
I'm looking for a way to detect if another process has a file open
before a


Make certain you know it exists, then,
Try to open the file exclusively,
an error means it is in use.


I'm not proposing a better solution, but I'm pretty sure using error-
trapping or exception handling to test for a thoroughly possible condition
like this would not qualify as a "best practice"...

--
Michael Kellogg

Nov 21 '05 #5
It's 'The eternal question', then...

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:uO******** ******@TK2MSFTN GP15.phx.gbl...
Glen,

This is endless asked, however this is as long as there are the MS-dos
operating systems and its successors not possible when you don't create a
special management tool around it, as probably in Office is done.

Cor

Nov 21 '05 #6
glen,

Answers on this are

do while loop condition = false
Try
Open a file
When found leave set the condition to true
Catch
threading.threa d.sleep(1000)
'And set a max if you want
End

I hope this helps something

Cor
Nov 21 '05 #7
Interesting.... I'll try that. Thanks.

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:uf******** ******@tk2msftn gp13.phx.gbl...
glen,

Answers on this are

do while loop condition = false
Try
Open a file
When found leave set the condition to true
Catch
threading.threa d.sleep(1000)
'And set a max if you want
End

I hope this helps something

Cor

Nov 21 '05 #8

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

Similar topics

5
12597
by: Jole | last post by:
Hi I'm writing a program that needs to read from a file. In order for the program to be robust, it should somehow check that the file isn't corrupt, or stuffed in any way. For example, that file may have been created but a crash occurred at that point in time (while it was being created), damaging the file. Now, my program which needs to read from this file, should first check that it's in good condition, and that it hasn't been...
7
2355
by: fox | last post by:
Maybe this is not the best group to ask this question, but I don't know a better one. I'm looking for a *portable* program in C (I mean source code) to detect whether unaligned word access is: a. handled by the main processor (e.g. x86) b. not supported (e.g. Sparc running Solaris) c. emulated in software (e.g. Alpha running Linux) By "unaligned word access" I mean access to a 16-bit word
2
15236
by: Anthony | last post by:
In C++ you can detect the screensaver state by using something like: BOOL b=SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, NULL, &bOn, FALSE); Is there an equivalent method that I can use in C#? If not, how can I determine the state of the screen saver? -- -Anthony
6
3642
by: Andrea | last post by:
I need to detect when another application is launched. I'd need to know also when a new folder is opened in explorer. I'm developing an application to speed up access to frequently used applications.
0
1070
by: Adrian Bezzina | last post by:
I am setting a session variable, then doing a server.transfer in global.aspx and the page I am going to is saying that session state is not enable and that I should enable it in either the page directive or web.config file. it is enabled in both has anyone else had similar problems? Adrian
2
1802
by: Robin Tucker | last post by:
In the absence of IAdviceSink support in .NET (well, not the pure vanilla COM version anyway), I need to be able to tell when another process has saved changes to a file, in a similar way some programs state "file has changed on disk, reload?". I was wondering what strategy I should use in order to check temp files I have created to see if they have been changed by another process. My initial thought is to periodically check the files,...
8
5127
by: dagecko | last post by:
Hi I would like to know how to detect if a file is binary or not. It's important for me but I don't know where to start. Ty
12
1983
by: ABN | last post by:
I have a C# (.NET 1.1) application in which I loop over a number of files on the hard drive and delete them. A few times, I've experienced an exception that says the file is in use by another process. So, my question is... Is there anyway to loop over the files and determine if the files are able to be deleted before trying to delete (so the exception won't be thrown)? Thanks.
5
8781
by: Z.K. | last post by:
In C#, using the StreamReader, how do I detect when you get to the end of line. I am reading a text file using the Read() function and I need to detect the \n\r, but everything I try does not work. I am sure that this probably fairly simple, but I have not been able to figure it out. Z.K.
0
9663
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10193
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9016
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6761
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4089
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.