Is there a way to copy (or cut) a file to the Windows clipboard from the command line?
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.
OK, it seems the easiest way was to create a small C# tool that takes arguments and stores them in the clipboard:
2017 edit: Here's a github repo with both source and binary.
You can try Swiss File Knife (SFK):
Example: turn backslashes into forward slashes. Imagine you have the following text open within Notepad:
And for some reason you need the first line in a format like this:
Then you may do it this way:
On the Windows command line, run this command (for example, from a batch file):
Back in the editor, press Ctrl + V or Shift + Insert, pasting the result from the clipboard.
As you see, the line changed into "foo\bar\systems\alpha1.cpp".
copy
andmove
are (some of) the batch commands that copy/paste and cut/paste files, respectively. We don't use the terms paste or cut when dealing with files but if I understand you there is a need to copy a file to another location and to move files to another location.I've forever wanted this to use in Emacs, so, inspired by this question, an answer here, and a goodly amount of NIH syndrome, I've written a C version available at
https://github.com/roryyorke/picellif
picellif also handles wildcards (it's not clear to me if rostok's C# version does or not).
You can use Command Line File Copy and Paste utilities available here : http://sbytestream.net/Software/Detail/2
This would place the contents of the file into the clipboard (accomplished by clip.exe).
To get the actual file, you'll probably have to resort to some other programming language, like VBScript or PowerShell to access Windows API's. I'm not entirely certain what Explorer puts into the clipboard when you CTRL+C a file. I suspect it uses the notification system to do something more intelligent than put the path to the file there. Depending on the context of the CTRL+V, you'll get something (Explorer, Word) or nothing (Notepad).