Is there some way to determine whether the file is in use? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
xin.songtao
Experienced Solver
Experienced Solver
Posts: 86
Joined: Wed Apr 18, 2007 6:10 am
Location: Shanghai China

Is there some way to determine whether the file is in use?

Post by xin.songtao » Sun Feb 07, 2010 9:10 am

Hi, everyone.

I create a file,and then open it with other apps or process(such as Firefox,IE),and when create the file again, I should determine isopend or not, and alert the user to close first.

Is there some way can be achieved?

thanks.
from: Shanghai China
language: C++/C
platform:MSW\MacOS\Linux
Email: [email protected]

yuri
Earned some good credits
Earned some good credits
Posts: 104
Joined: Thu Apr 09, 2009 4:58 pm
Location: Russia

Post by yuri » Sun Feb 07, 2010 9:18 am

if that another app uses file locks than yes. You may query existing locks and act appropriately.

However most often application would open file, read it, close it immediately, then proceed to display its contents. That way, file is long closed and not used at all even if its content is still on screen.

xin.songtao
Experienced Solver
Experienced Solver
Posts: 86
Joined: Wed Apr 18, 2007 6:10 am
Location: Shanghai China

Post by xin.songtao » Sun Feb 07, 2010 9:57 am

if that another app uses file locks than yes. You may query existing locks and act appropriately.
I generated a video,and embedded it in a Web page, open it with the browers(such as Firefox,IE).

How to query the existing locks? Is there some way in wxWidgets?


Thanks for your reply.
from: Shanghai China
language: C++/C
platform:MSW\MacOS\Linux
Email: [email protected]

User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2293
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Post by evstevemd » Sun Feb 07, 2010 3:09 pm

There is function called isopen()
I dont remember where but it is in file. Just search wxDocs for that word.
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
[Ubuntu 19.04/Windows 10 Pro/MacOS 10.13 - GCC/MinGW/Clang, CodeLite IDE]

xin.songtao
Experienced Solver
Experienced Solver
Posts: 86
Joined: Wed Apr 18, 2007 6:10 am
Location: Shanghai China

Post by xin.songtao » Tue Feb 09, 2010 9:31 am

Hi,
I use this code to test if the

Code: Select all

fileToWrite
is using.

Code: Select all

wxFile file(fileToWrite);
if (file.IsOpened())
{
wxMessageBox( _("The files are used. Please close the browser before proceeding."));
			return false;
}
but the first time,this is ok,but the following it always return false(IsOpend() return true);

At last, I have to remove the file for test.

Code: Select all

if (wxRemoveFile(fileToWrite)==false)
{
wxMessageBox( _("The files are used. Please close the browser before proceeding."));
			return false;

}
from: Shanghai China
language: C++/C
platform:MSW\MacOS\Linux
Email: [email protected]

Post Reply