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

Locked files

How can you tell if a file is locked/being written to by another process?

-Cam
Nov 17 '05 #1
3 1793
Joe
Hi Cameron,

What I did was verify that the file exists and than attempt to open the file
in ReadWrite mode. If this fails, I than try to open in Read mode. If it
still fails, than the file is open and locked for exclusive access.

-Joe

"Cameron" <ca*****@appdepot.com> wrote in message
news:11*************@corp.supernews.com...
How can you tell if a file is locked/being written to by another process?

-Cam

Nov 17 '05 #2
Doesn't that seem excessively heavy? If you look at something like
handle.exe, it can give you a complete list of all of the locked files
on your system, (really quickly), but some how I can't see it attempting
to open every file in write mode.

There has to be a API somewhere that can give this type of information.

-Cam

Joe wrote:
Hi Cameron,

What I did was verify that the file exists and than attempt to open the file
in ReadWrite mode. If this fails, I than try to open in Read mode. If it
still fails, than the file is open and locked for exclusive access.

-Joe

"Cameron" <ca*****@appdepot.com> wrote in message
news:11*************@corp.supernews.com...
How can you tell if a file is locked/being written to by another process?

-Cam


Nov 17 '05 #3
No it's not that heavy, beside, Handle.exe doesn't give you the information
you really need, it only says that a (file)handle is associated with a
certain file, but it doesn't say how the file is opened and how it can be
shared.
It's not because a file is opened by process A that it cannot be used by
process B, all depends on the open mode and the share mode, no-one stops you
from opening a file in read mode multiple times, note that it's even
possible to open a file for shared write access, how would handle.exe be of
any help here?

Willy.

"Cameron" <ca*****@appdepot.com> wrote in message
news:11*************@corp.supernews.com...
Doesn't that seem excessively heavy? If you look at something like
handle.exe, it can give you a complete list of all of the locked files on
your system, (really quickly), but some how I can't see it attempting to
open every file in write mode.

There has to be a API somewhere that can give this type of information.

-Cam

Joe wrote:
Hi Cameron,

What I did was verify that the file exists and than attempt to open the
file in ReadWrite mode. If this fails, I than try to open in Read mode.
If it still fails, than the file is open and locked for exclusive access.

-Joe

"Cameron" <ca*****@appdepot.com> wrote in message
news:11*************@corp.supernews.com...
How can you tell if a file is locked/being written to by another process?

-Cam



Nov 17 '05 #4

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

Similar topics

0
by: Neil | last post by:
Hi, I posted this on the dotnet.framework newgroup, but no one replied, so I thought maybe this newsgroup might help. I'm writing a file utility and would like my program to at least try to...
10
by: Martin Ho | last post by:
I am running into one really big problem. I wrote a script in vb.net to make a copy of folders and subfolder to another destination: - in 'from.txt' I specify which folders to copy - in...
4
by: Qwert | last post by:
Hello, I have a listview with an image list. After dispoing the images and the image list, the bitmap files remain locked: REM Create. objImage = Image.FromFile(strBmp) If...
5
by: cmay | last post by:
The only examples I have seen on how to check if a file is locked is to try to open it a catch an exception. MS has stated that you should never use error trapping in this manner. Is there no...
3
by: Kirt | last post by:
i have a code that backsup file from src to dest. Now if some of the files are locked , i need to skip those files.. I was trying to use fctl module but it can be used only in unix i suppose. ...
6
by: elake | last post by:
I found this thread about a pst file in Windows being locked and I am having the same issue. ...
5
by: Glen Buell | last post by:
Hi all, I have a major problem with my ASP.NET website and it's SQL Server 2005 Express database, and I'm wondering if anyone could help me out with it. This site is on a webhost...
3
by: rubbishemail | last post by:
Hello, do you know of any way to copy locked / opened files under win xp? I know there is something like "Volume Shadow Copy" but I don't know how to use it. Maybe someone already has a python...
5
by: Markus Erlacher | last post by:
Hi Newsgroup, I have a problem that is not directly C#-related, but I'd like to solve it in C#. A data acquisition station generates heaps of data, which shall be transferred to a server. As...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.