Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Movefile function works too well...

Posted on 2007-11-14
6
1,232 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
can't find the executable in Simulator 1 100
tidtcpserver connection lost handle 2 102
Base1 Encode/Decode 3 81
Installshield for Embarcadero EX 10.1 Berlin 4 60
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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