9

Is there a way or program to copy content of .txt file to clipboard without opening it?

Now I have to open->ctrl+a->ctrl+c->close. A little bit annoying if you do it often.

Is there a possible shortcut for this operation?

3 Answers 3

17

There's a clipboard utility in Windows called clip.exe.

In the command prompt, you can copy the contents of a file to your clipboard using

clip < file.txt

This will be useful if you use the command prompt often. If you don't, you can add it to your context menu. I've just tested this out with instructions from HowToGeek on Windows 7, but I had to make a little tweak before I got it to work.

HowToGeek has also mentioned that clip.exe does not come with XP, so you'll have to download it from Microsoft FTP here and place it in your Windows system directory.

Steps:

  1. Open regedit.exe
  2. Go to HKEY_CLASSES_ROOT/txtfile/shell (This didn't work for me so I had to put it under HKEY_CLASSES_ROOT/*/shell, which makes it show up in EVERY context menu)
  3. Add a new key titled copytoclip
  4. Set the default value of copytoclip to something like Copy to Clipboard
  5. Under copytoclip, add a key called command
  6. Set the default value of command to cmd /c clip < "%1"

Now whenever you right click on a file, you should see a Copy to Clipboardoption. What it does it that when you click on it, it will open a command prompt and run the clip.exe utility on the output piped from the file you selected.

1

For XP I generally us the Send To X powertoy available from Microsoft.

http://technet.microsoft.com/en-us/library/cc751394.aspx

And while I'll probably go with Jin's answer which I also upvoted on Win7. One of the things I love about SendToX is the send to clipboard as name. I have probably averaged 4 uses per day of this since it came out with Win95.

0

Since you're looking to copy the text, just pipe the contents to the clipboard.

type file.txt | clip
4
  • This is a repeat of a small portion of the first answer –– from almost two years ago. Commented Aug 13, 2013 at 0:21
  • Actually the first answer does not use either the pipe "|" or the "type" keyword and the "<" operator is 'reserved for future use' in PowerShell and a few others. The method I suggest is also useful, different, and has the advantage of not requiring a registry edit...it just does what it should. Having a bad day Scott? Commented Aug 15, 2013 at 5:59
  • A fascinating tidbit of trivia, but irrelevant to this question. Nothing here mentioned PowerShell until you brought it up. clip < file.txt works fine in the Command Prompt, and it doesn’t require a registry edit unless the user wants to add it to the context menu –– and, since you haven’t said otherwise, I assume the same is true of your answer. OK, I’ll concede that your answer is useful. And, technically, it’s different –– the way a purple wheel differs from a black wheel. It’s still a wheel. Commented Aug 15, 2013 at 23:18
  • 1
    I posted this method because the accepted answer does not work in my scenario... and the question (still) doesn't state a flavor of command prompt. My method doesn't depend on what prompt you use. So, this is just a wheel...the purple wheel only goes on the purple car. :) Commented Aug 16, 2013 at 3:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .