感谢 Stack Overflow 的问题 Copy files to clipboard in C#,我能够使用 Clipboard.SetFileDropList 并最终实现:
using System;
using System.Collections.Specialized;
using System.Windows.Forms;
class Program
{
[STAThread]
static void Main ( string[] args)
{
StringCollection paths = new StringCollection();
paths.Add( @"C:\Users\Antonio\Desktop\MyDirectory" );
Clipboard.SetFileDropList( paths);
}
}
这样我就可以将整个目录放在剪贴板上,然后粘贴到需要的位置。但是我希望能够用代码粘贴它。我不想去要粘贴的位置然后按 Ctrl + V。换句话说,我正在寻找像这样的东西:
Clipboard.Paste("C:\Users\LocationWhereIWantToPasteTheFolder")
我知道可以递归获取所有文件,然后一个一个粘贴。但是为什么要重新发明轮子呢?如果操作系统可以为我完成这个任务,那就太好了...