如何复制/剪切一个文件(未内容)到剪贴板中的Windows命令行? [英] How to copy/cut a file (not the contents) to the clipboard in Windows on the command line?
本文介绍了如何复制/剪切一个文件(未内容)到剪贴板中的Windows命令行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法将文件从命令行复制(或剪切)到Windows剪贴板?
Is there a way to copy (or cut) a file to the Windows clipboard from the command line?
在特别批处理脚本。我知道如何将内容复制到剪贴板(文件类型|夹
),但事实并非如此。我希望有,因为我想$ P $整个文件PSS <大骨节病>控制骨节病> + <大骨节病> C 骨节病>在Windows资源管理器。
In particular with a batch script. I know how to copy the contents to the clipboard (type file | clip
), but this is not the case. I want to have the whole file as I would press Ctrl + C in Windows Explorer.
推荐答案
确定,似乎最简单的方法是创建一个小的C#工具,它的参数,并将其存储在剪贴板中:
OK, it seems the easiest way was to create a small C# tool that takes arguments and stores them in the clipboard:
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Collections.Specialized;
namespace File2Clip
{
public class App
{
[STAThread]
static void Main(string[] args)
{
List<string> list = new List<string>();
string line;
while(!string.IsNullOrEmpty(line = Console.ReadLine())) list.Add(line);
foreach (string s in args) list.Add(s);
StringCollection paths = new StringCollection();
foreach (string s in list) {
Console.Write(s);
paths.Add(
System.IO.Path.IsPathRooted(s) ?
s :
System.IO.Directory.GetCurrentDirectory() +
@"\" + s);
}
Clipboard.SetFileDropList(paths);
}
}
}
这篇关于如何复制/剪切一个文件(未内容)到剪贴板中的Windows命令行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文