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

本文关键字:进程 因为 另一个 访问 文件 | 更新日期: 2023-09-27 18:32:30

我正在尝试移动图像文件,但出现错误。我确定该文件不是从另一个外部程序打开的。我重新启动了计算机,没有任何变化。为什么我会收到此错误?是关于DirectoryInfo吗?

DirectoryInfo di = new DirectoryInfo("C:''gphoto-2.4.14-win32-build2''win32");
                FileInfo[] smFiles = di.GetFiles("*.jpg");
                if (smFiles!=null)
                {
                    string from = "C:''gphoto-2.4.14-win32-build2''win32''capt0000.jpg";
                    string to = System.Reflection.Assembly.GetEntryAssembly().Location + "''capt0000.jpg";
                    File.Move(from, to); // Try to move
                }

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

因为System.Reflection.Assembly.GetEntryAssembly().Location是文件而不是目录。

请改用System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)

相关文章: