我将文件从一个文件夹移动到另一个文件夹.如果我尝试将整个文件夹移动到该特定文件夹中的文件夹,我就无法这样做.但如果我把它移到外面就可以了.如何将文件夹移动到该文件夹中的文件夹?
这给出了错误
if (System.IO.Directory.Exists(PhysicalPath))
{
string sourcePath = "c:\\copypath\\";
string targetPath = "c:\\copypath\\abc\\";
System.IO.Directory.Move(sourcePath, targetPath);
}
Run Code Online (Sandbox Code Playgroud)
这很好用
if (System.IO.Directory.Exists(PhysicalPath))
{
string sourcePath = "c:\\copypath\\";
string targetPath = "c:\\abc\\";
System.IO.Directory.Move(sourcePath, targetPath);
}
Run Code Online (Sandbox Code Playgroud)
尝试"c:\ copypath \"进入"c:\ copypath\abc \"将无法正常工作,因为它没有意义.
如果你移动copypath文件夹然后它将不再存在,那么它的目标文件夹(它是一个子文件夹)将如何存在?
您可以将"c:\ copypath \"的所有子文件移动到"c:\ copypath\abc \"中,这不会导致问题(再次假设您不尝试将abc复制到自身中).