"Active" files and moving/changing paths

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jul 2005
Posts: 244
Reputation: Drowzee is an unknown quantity at this point 
Solved Threads: 5
Drowzee Drowzee is offline Offline
Posting Whiz in Training

"Active" files and moving/changing paths

 
0
  #1
Jun 16th, 2006
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.
Explainer of control logic and some basics.
"If you seek to drink from a fountain of knowledge, make sure your cup is big enough."
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: "Active" files and moving/changing paths

 
0
  #2
Jun 17th, 2006
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.
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.
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 244
Reputation: Drowzee is an unknown quantity at this point 
Solved Threads: 5
Drowzee Drowzee is offline Offline
Posting Whiz in Training

Re: "Active" files and moving/changing paths

 
0
  #3
Jun 17th, 2006
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.
Explainer of control logic and some basics.
"If you seek to drink from a fountain of knowledge, make sure your cup is big enough."
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 244
Reputation: Drowzee is an unknown quantity at this point 
Solved Threads: 5
Drowzee Drowzee is offline Offline
Posting Whiz in Training

Re: "Active" files and moving/changing paths

 
0
  #4
Jun 19th, 2006
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.
Explainer of control logic and some basics.
"If you seek to drink from a fountain of knowledge, make sure your cup is big enough."
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC