我在这次尝试中使用C#作为编程语言。
我在无数论坛和其他Google搜索结果中寻找答案,但是我找不到我的问题的解决方案。
我有一个FileExplorer并且我在我的ContextMenuStrip组件中有复制/粘贴/删除菜单项。现在,我已经能够复制文件在我的File Explorer中,但是我正在尝试弄清楚如何复制文件夹。
我使用TreeView组件作为我的主要组件,并将其绑定到此操作。
什么是文件管理器?这是我所说的内容(这是我的文件资源管理器的实际图像):
这是我当前用于在“FileExplorer\”文件夹内部复制“文件”的代码。它还检索'FileExplorer\'文件夹中的其他文件夹/文件。
我在无数论坛和其他Google搜索结果中寻找答案,但是我找不到我的问题的解决方案。
我有一个FileExplorer并且我在我的ContextMenuStrip组件中有复制/粘贴/删除菜单项。现在,我已经能够复制文件在我的File Explorer中,但是我正在尝试弄清楚如何复制文件夹。
我使用TreeView组件作为我的主要组件,并将其绑定到此操作。
什么是文件管理器?这是我所说的内容(这是我的文件资源管理器的实际图像):
![enter image description here](https://istack.dev59.com/U3i7m.webp)
private void toolStripMenuItemCopy_Click(object sender, EventArgs e)
{
try
{
DirectoryInfo[] directories = directoryInfo.GetDirectories();
foreach (FileInfo file in directoryInfo.GetFiles()) // Retrieving the files inside of FileExplorer\ folder
{
if (file.Exists && file.Name == treeView.SelectedNode.Text)
{
StringCollection filePath = new StringCollection();
filePath.Add(file.FullName);
Clipboard.SetFileDropList(filePath); // Copying the selected (node) file
}
}
if (directories.Length > 0)
{
foreach (DirectoryInfo directory in directories) // Retrieving the directories inside of the FileExplorer\ folder
{
foreach (FileInfo file in directory.GetFiles()) // Retreiving all the files inside of the directories
if (file.Exists && file.Name == treeView.SelectedNode.Text)
{
StringCollection filePath = new StringCollection();
filePath.Add(file.FullName);
Clipboard.SetFileDropList(filePath); // Copying the selected (node) file
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
如果有人能给我提供关于如何在文件资源管理器中复制文件夹的指针/代码,那将不胜感激!