Solved

Movefile function works too well...

Posted on 2007-11-14
6
1,222 Views
Last Modified: 2013-11-22
Hi,

I'm working on a program wich will move a lot of file to another directory...  If the moving was a success it return me true, if not, it return me false.

In some case, it's  possible that the file will be open and thats normal.  than i expect windows to return me a false operation.  but is not.  the movefile fonction move the file anyway!  that's a problem.!!!!    I made some test and notice that if the file is completely open in memory, like a file in notepad, windows dont care about it and move it... wich causing a trouble when the person want to save that file...   If the file is too big... like AVI file, than it return me the error i expect...  

My questions is .... it is normal?  Is this another weird hiding windows settings?

Thank you very much!

0
Comment
Question by:Fled
6 Comments
 
LVL 19

Accepted Solution

by:
MerijnB earned 250 total points
ID: 20284313
This depends on how the application works which opens the file.

Notepad reads a file completely into memory and writes it completely when you save the file.
A large AVI file is being streamed while playing (only a part of the file is kept in memory).

This explains why you can move one file, and you can not move another.

When you open a file from your application you can give flags on what other processes can do with this file (cannot write, cannot read, etc).
0
 
LVL 25

Assisted Solution

by:imitchie
imitchie earned 250 total points
ID: 20284940
As MerijnB has said, notepad takes a copy of the file into memory completely. When you save, it writes it down from memory, so if you moved the file, it will create a new one, using the previous name when it opened it.  You have no way of knowing if someone has "photocopied" the file into memory.

Other applications specify "open for shared read", "open for exclusive write" etc.. which will block you from moving the file.  This is all normal behaviour
0
 

Author Comment

by:Fled
ID: 20287086
hummm...

So the system dont gave me much choice to detect if it's open first???
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 25

Expert Comment

by:imitchie
ID: 20287145
i'll let someone correct me on this, but not that i know of
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 20287965
if an application (like notepad) just reads the file and closes it again, no you cannot
0
 
LVL 21

Expert Comment

by:developmentguru
ID: 20288895
The only time I have been able to accomplish such a feat is when I started the program that opened it.  All I was able to determine then was if the program was still open (and therefore the file could still be in use).  If you wrote the program that opened the file then you can try to communicate with it (via messaging or some other method) to see if any version of it has your file open.  Many programs will show the file name in the caption (such as notepad) and you could search for that within the list of open windows.  While I hate to hear that something "can't be done" we are limited to the tools that Windows provides.  Even using some of the approaches I mentioned here, there is no fullproof way that I know of.  As has been stated previously, once a file is opened - read - and closed there is no clue that the program that did it is using the data from it unless the program maintains a tie to the file.

I hope that helps.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now