简体   繁体   English

如何将目录的数据移动到父路径

[英]How to move directory's data to parent path

I have a problem when I move data from a directory to it's parent, my code: 将数据从目录移动到其父目录时,我遇到了一个问题:

string resDirectory = "d:\\data";
DirectoryInfo di = new DirectoryInfo(resDirectory);

if (Directory.Exists(resDirectory))
Directory.Move(di.FullName, di.Root.ToString());

but when I run it I get the following error: 但是当我运行它时,出现以下错误:

The parameter is incorrect.

how can I do it? 我该怎么做?

Directory.Move needs a source FOLDER and a destination FOLDER. Directory.Move需要一个源文件夹和一个目标文件夹。

Say you want to move the directory c:\\temp to d:\\asdf . 假设您要将目录c:\\temp移至d:\\asdf This will move the contents of the folder AND rename the folder from "temp" to "asdf". 这将移动文件夹的内容,并将文件夹从“ temp”重命名为“ asdf”。

So, how can you move a folder and rename it to d:\\ ? 因此,如何移动文件夹并将其重命名为d:\\

In your example, you can't move the folder up any higher. 在您的示例中,您无法将文件夹上移。 The folder is already at the root of the drive. 该文件夹已经在驱动器的根目录中。 You need to move the files inside up higher. 您需要将文件内部向上移动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM