Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Movefile function works too well...

Posted on 2007-11-14
6
Medium Priority
?
1,246 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 750 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 750 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

963 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