Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Windows API to programmatically Cut / Copy / Paste files via Windows Explorer?

I know that SHFileOperation can be used to perform file operatons with Windows Explorer, but it only performs complete file operations where both the source and destination are known.

Is there an API that allows a application to cut, copy, or paste in Windows Explorer from an application?

To answer a couple of questions:

  • Using Windows Explorer to perform file/folder operations would greatly simplify moving multiple objects. This is particularly important for moving folders and their contents since MoveFile does not support moving folders to different volumes.

  • Using Windows Explorer to perform file/folder operations would allow the operations to be added to Windows Explorer’s undo buffer so that they can be undone, otherwise operations done with console applications/the command-prompt cannot be undone.

I am sure that I have seen it possible to perform Windows Explorer verbs programmatically, but I can’t seem to find a way to do so for these.

like image 958
Synetech Avatar asked Mar 23 '12 19:03

Synetech


People also ask

How do I cut and paste in File Explorer?

Then press either the “Ctrl” + “C” keys on your keyboard to copy the item or the “Ctrl” + “X” keys on your keyboard to cut the item. Then use File Explorer to navigate into the folder into which to paste the item you just cut or copied.

Why can I not copy and paste in File Explorer?

One of the most common causes of copy and paste issues on Windows is when an installed application is interfering with the clipboard. Uninstall those applications to see if that fixes the issue. If you struggle to remove them, try using uninstaller programs to force delete them. Scan for viruses or malware.

What is clipboard in File Explorer?

The clipboard, also known as pasteboard, is a particular location on a computer, phone, or tablet memory that temporarily stores cut or copied text or other data. Once something is stored in the clipboard, it can be pasted to a new location.


1 Answers

It's difficult to imagine why such a function would exist, or what good it would be if it did.

Cut/copy and paste are provided for the convenience of the user. It allows them to move/copy something somewhere else at a later date. The application that implements cut/copy and paste functionality may not know where the data is ultimately going to be pasted, but that's okay because the user still knows.

But an application doing a cut/copy-paste action doesn't make a lot of sense because in order for the "paste" part to work, the application has to know where the item is going to be pasted. And if it knows that, then it could just call the SHFileOperation function that you already know about.

If you are really just talking about providing the user with the ability to cut/copy/paste an item, then you will want to use the clipboard—just like Windows does. When an item is cut or copied, it's placed on the clipboard. When an item is pasted, the current contents of the clipboard are retrieved. Use the Windows clipboard API functions to interact with the clipboard.

like image 50
Cody Gray Avatar answered Sep 30 '22 05:09

Cody Gray