Click to See Complete Forum and Search --> : File::Move(..) = error
Raiderski
April 11th, 2005, 03:13 AM
Hello!
I'm using vs.net2003 with .net1.1 and i have trouble with:
File::Move(src, dest);
and
File::Copy(src,dest);
File:: Delete(src);
I have strange message:
"The process cannot access the file because it is being used by another process".
What the ****? Dest file doesn't exist before File::Move() so how it could bu used by other process? I'm 100% sure that the files aren't used by other process! Help!
NoHero
April 11th, 2005, 03:35 AM
Well... Are you really sure that it is not reserved by another process? Have you tried to access them manually from the explorer...
Raiderski
April 11th, 2005, 03:52 AM
Well yes ofcourse I'm sure, beside dest file doesn't even exist! That's normal because I only want to replace src file name to the name defined in dest. File::Move(src, dest) should do that but it won't.
NoHero
April 11th, 2005, 04:25 AM
So I guess you are trying to rename the file? :confused:
Raiderski
April 11th, 2005, 06:06 AM
Yep. I've looked in MSDN, there isn't Rename() function, instead is Move().
NoHero
April 11th, 2005, 08:38 AM
Then give me your source code and/or the file name's and their access rights...
Raiderski
April 11th, 2005, 02:12 PM
void SaveImage(TileImage* ti)
{
String* srcFile = String::Format("{0}{1}", ti->path, ti->name);
String* destFile;
int i = 1;
try {
if (File::Exists(srcFile)) {
int s = srcFile->LastIndexOf(".");
do {
destFile = srcFile->Insert(s, i.ToString());
++i;
} while(File::Exists(destFile));
File::Move(srcFile, destFile);
}
ti->image->Save(srcFile, Imaging::ImageFormat::Png);
}
catch (Exception* e) {
// handle exception
}
}
Hm... there isn't probably problem with Move() only because I also try:
Diagnostics::Process* rename = new Diagnostics::Process();
String* params = String::Format("/K rename {0} {1}", srcFile, destFileName);
rename->Start(S"cmd", params);
And still sometimes don't have access to file :/ Yes, I wrote "sometimes" because the problem doesn't occur everytime.
Raiderski
April 11th, 2005, 04:46 PM
Whoa! I cannot believe... file is locked during loading with method:
Bitmap* img = new Bitmap(String* filename);
But when I use method:
Bitmap* img = new Bitmap(Stream*);
Everything is fine! Completly amazing :/
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.