Solved

Movefile function works too well...

Posted on 2007-11-14
6
1,235 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help on project with Soap 10 62
Tviruailstringtree sort multi columns on header click 1 84
Get weeknumber and year from date 4 26
Broadcast a message using ICS 2 21
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

756 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