我正在将文件从一个文件夹移动到另一个文件夹。如果我尝试将整个文件夹移动到该特定文件夹中的文件夹,我将无法执行此操作。但是,如果我将它移到外面,它就可以正常工作。如何将我的文件夹移动到该文件夹中的文件夹?
这会产生错误
if (System.IO.Directory.Exists(PhysicalPath))
{
string sourcePath = "c:\\copypath\\";
string targetPath = "c:\\copypath\\abc\\";
System.IO.Directory.Move(sourcePath, targetPath);
}
这很好用
if (System.IO.Directory.Exists(PhysicalPath))
{
string sourcePath = "c:\\copypath\\";
string targetPath = "c:\\abc\\";
System.IO.Directory.Move(sourcePath, targetPath);
}
最佳答案
尝试将“c:\copypath\”转换为“c:\copypath\abc\”是行不通的,因为它没有意义。
如果你移动了copypath文件夹,那么它就不存在了,那么它的目标文件夹(它是一个子文件夹)将如何存在?
您可以将“c:\copypath\”的所有子文件移动到“c:\copypath\abc\”中,这不会导致问题(再次假设您不尝试将 abc 复制到本身)。
关于c# 文件移动(文件已被另一个进程使用),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5633505/