且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我希望从一个文件夹中的文件移动到另一个文件夹。

更新时间:2022-12-03 21:45:18

这意味着什么:文件正在使用中。它可能是您当前的应用程序,也可能是另一个应用程序:但最有可能的是,当您创建文件时,您没有关闭并处理您正确使用的所有内容,因此文件将一直使用,直到应用程序结束,或垃圾收集器被执行以清理你身后。检查用于创建文件的代码。
It means what is says: the file is in use. It could be your current application, or it could be a different one: but the most likely is that when you created the file you didn't close and dispose of everything you used correctly, so the file remains in use until the app ends, or the garbage collector gets executed to clean up behind you. Check the code you used to create the file first.


引用:

该进程无法访问该文件因为它正由另一个进程使用

The process cannot access the file because it is being used by another process





这意味着您尝试移动的其中一个文件在另一个程序中打开。检查一下。



另外,我会添加一些错误处理,以查看哪个文件是移动时出错的文件。这样的事情:





This means that one of the files you are trying to move is opened in another program. Check that.

Plus, I would add some error handling to see which file was the one which gave error while moving. Something like this:

string newdir = Server.MapPath("temp/hotelimg/");
foreach (var file in Directory.GetFiles(Server.MapPath("images/hotelpic/")))
{
    try
    {
        string FileName = Path.GetFileName(file);
        File.Move(file, Path.Combine(newdir, FileName));
    }
    catch(Exception ex)
    {
        Console.WriteLine("string.Format("Error while moving File : {0}. Error Message: {1}", file, ex.Message));
    }
}