Solved

Movefile function works too well...

Posted on 2007-11-14
6
1,240 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
[X]
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
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
Technology Partners: 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

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

751 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