473,699 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do i find out if a file is locked?

73 New Member
How can I determine if the file is locked. I have looked everywhere and I get mixed answers and I can't get this going.

I know this is easy for some, but please post a quick sol.

Thanks.
Jan 13 '09 #1
34 22349
donbock
2,426 Recognized Expert Top Contributor
Who [what application] is locking the file in question and how is it being accomplished?

A file might be locked via a system call -- you need to tell us what operating system you're using.

Some applications perform their own ad-hoc file locking and unlocking -- you need to tell us what application.

In either case, it should be clear that file locking is idiosyncratic. There is no single portable way to determine if a file is locked.
Jan 13 '09 #2
gpraghuram
1,275 Recognized Expert Top Contributor
This is one of a common question and the answer is no.
There is no system call to do this

Raghu
Jan 14 '09 #3
sevak316
73 New Member
I am running Windows XP.

The file is being locked by a 3rd party software. As far as I am concerned the application is doing the locking and unlocking.

This is what happens:
I create a project using this application. The project has x number of files. When the project is open, one file (JUST ONE) gets locked.

gpraghuram - you mentioned that there is no way to determine if a file is locked. I use winzip to zip/backup the project files at least once a day. Winzip notices that this file cannot be zipped due to the fact that it is being used.

This is the error I get from winzip after trying to zip the project files while the project is up and running.

Warning: The following file is open by another program. If that program
Warning: writes to the file while WinZip is zipping the file, the zipped
Warning: file may be corrupt: C:\Rhapsody\Mod el\JDW341\myscr ipts.vba

My question is, how does Winzip know? That is the same function/api call that I am looking for in my program that I am writing.

Do you guys have any ideas?
Jan 14 '09 #4
Banfa
9,065 Recognized Expert Moderator Expert
WinZip noticed because it tried to open the file and was unable to, you could try the same thing but the important point is that it is non-portable and just being able to open a file doesn't mean another program isn't using it.
Jan 14 '09 #5
sevak316
73 New Member
I see what you mean.
In my case it should be ok since that file will only open by that specific program.

Thanks.
Jan 14 '09 #6
sevak316
73 New Member
I dont think opening the file is cutting it. I open the file with no errors. I believe it might be when you try to save it.

I can't imaging Winzip trying to save every file to see if it can copy it or not. :\
Jan 14 '09 #7
Banfa
9,065 Recognized Expert Moderator Expert
try opening it for write access
Jan 14 '09 #8
sevak316
73 New Member
this is what i have:

#include <iostream>
#include <fstream>
using namespace std;

int main ()
{
ofstream myfile ("C:\\Rhapsody\ \Model\\JDW341\ \LR240.vba");

if (myfile.is_open ())
{
cout << "access granted.\n";
system("PAUSE") ;
myfile.close();
}

else { cout << "access denied.\n"; system("PAUSE") ; }
return 0;
}
Jan 14 '09 #9
weaknessforcats
9,208 Recognized Expert Moderator Expert
You might try using actual Win32 calls to get your file access instead of just using ANS C++. As far as ANS C++ goes, if the file exists, it will open.

System Software Win32 File API
Jan 14 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
7323
by: Pekka Niiranen | last post by:
Hi, I have used the following example from win32 extensions: -----SCRIPT STARTS---- import win32file import win32con import win32security import pywintypes
0
3935
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header, example, and DLL:...
5
1523
by: Fabio R. | last post by:
To support a webfarm scenario, I'd like to store a global array (serialized) in a file on a network share. In this array there is a list of pages "locked" by other users so I need to read this array at every page access to detect if the page is "free" so the user can access it; when the user can access the page, the page is added to the array so the next user can't access. What's the best way to lock this (network) file so when 2 users...
4
2763
by: hkappleorange | last post by:
I ued this code to connect to a mdb file A = New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=C:\Inetpub\wwwroot\ASPX\Authors.mdb" )
0
2564
by: troutbum | last post by:
I am experiencing problems when one user has a document open through a share pointing to the web site. I use the dsolefile to read the contents of a particular directory and then display them in a datalist. When the next user selects trys to run the page, the page fails and I get a generic error message from the stack trace. I am assuming that the document properties cannot be read when a file is open, but it worked well in asp. ...
1
19933
by: ABCL | last post by:
Hi All, I am working on the situation where 2 different Process/Application(.net) tries to open file at the same time....Or one process is updating the file and another process tries to access it, it throws an exception. How to solave this problem? So second process can wait until first process completes its processing on the file. Thanks in advance
5
20275
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 other way to identify if a file is locked w/o trapping an exception?
11
8412
bhcob1
by: bhcob1 | last post by:
Hi, Whenever I delete a record my command button, the record deletes, a list displaying all records is updated and then a message box appears: Microsoft Access can't find the field 'I' referred to in your expression It only has the option of clicking 'OK', when I do this everything is fine again. I would like to know what is going on and how to fix this problem. Below is parts of the code that I believe the problem is in. The form is...
0
964
by: Dmitry Teslenko | last post by:
Hello! I use some script in python 2.5 from vim editor (it has python bindings) that updates some file and then launches another program (ms visual studio, for example) to do something with updated file. I faced problem when updated file is locked for writing until vim editor is closed. launch vim -update file -launch msvc -file locked launch vim -update file -launch msvc -close vim -file locked
0
1508
by: Gabriel Genellina | last post by:
En Tue, 13 May 2008 11:57:03 -0300, Dmitry Teslenko <dteslenko@gmail.com> escribió: Is the code above contained in a function? So all references are released upon function exit? If not, you could try using: del input, output, filter That should release all remaining references to the output file, I presume. Or locate the inner reference to the output file (filter.something perhaps?) and explicitely close it.
0
8694
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
8621
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9182
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8890
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
4379
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
4634
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3060
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
2355
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2013
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.