I have an application that is a substitute for Windows Photos that loads in some photos and whatever photo is of interest is marked as important. The way it is marked is that the picture is renamed so that a "#" precedes the original name, so "myPicture" becomes "#myPicture". I am having trouble renaming it, however. I am getting an error when I use functions like "MoveTo" to rename it and I believe it is because I have the picture loaded in the application at the same time so I am not able to access it. Is there a way to create a copy and swap it out with the original? Thank you.
CodePudding user response:
If your application is holding the file open using a FileStream
, then the application should be able to copy the byte stream of the file into a new file.
CodePudding user response:
If the application has the file open, MoveTo
and similar functions will not be able to move it. You might be able to open it from another process and copy it. It depends on whether you opened it with exclusive access. The application will have to open with FileShare.Read
if you want other processes to read the file while the application has it open. See FileStream constructor documentation for details.