943,696 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1808
  • C++ RSS
Jun 16th, 2006
0

"Active" files and moving/changing paths

Expand Post »
This is an offshoot of a specific problem I've posted in the C# forum.

However, it applies to C++ as well.

If you have opened a file, specifically, an image file, but would like to rename (or, as MSDN says, 'move) the directory the file resides in, what are the requirements for being able to move the directory without the system complaining about access violations?

The imagefile I'm using is opened in a picturebox control, but making the picturebox show another image does not help. Only the complete commenting out of code that loads information about the picture seems to help, but it's necessary for me to be able to view the picture both before and after the move/renaming.

Is there a way to unload, detach, or close a file from an application such that the parent directory can be moved without problems?

How does the application/OS recognize that it cannot move the active file?

Thanks in advance.
Similar Threads
Reputation Points: 22
Solved Threads: 5
Posting Whiz in Training
Drowzee is offline Offline
244 posts
since Jul 2005
Jun 17th, 2006
0

Re: "Active" files and moving/changing paths

Quote originally posted by Drowzee ...
Is there a way to unload, detach, or close a file from an application such that the parent directory can be moved without problems?
Yes. Refer the File Management Functions in MSDN.
Quote originally posted by Drowzee ...
How does the application/OS recognize that it cannot move the active file?
When an application opens the file, the programmer can set various sharing access rights so that the OS knows what to do when a request that affects the same file comes while that file is still open. You can see the list of flags that can be set under the Security Attributes section for CreateFile.
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Jun 17th, 2006
0

Re: "Active" files and moving/changing paths

That looks to be just about what I'm interested in; however, with regards to the PictureBox control specifically, how would you force it to release the file that has been set to its image attribute?

Would CloseHandle do this?
Or should I focus on the Image, and call its dispose function before eliminating the reference in the picturebox control?
The latter seems more likely. I'll try that on monday.
Reputation Points: 22
Solved Threads: 5
Posting Whiz in Training
Drowzee is offline Offline
244 posts
since Jul 2005
Jun 19th, 2006
0

Re: "Active" files and moving/changing paths

As I (eventually) figured out, with inspiration from Wolfpack's reply, making sure to explicitly mark the image for closing and garbage collection solved the problem nicely.

Thanks for the inspiration, and I'll keep the file functions you linked in mind.
Reputation Points: 22
Solved Threads: 5
Posting Whiz in Training
Drowzee is offline Offline
244 posts
since Jul 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Lol Im reallly new at this
Next Thread in C++ Forum Timeline: C++ CGI Scripts





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC