VSCode :: How can I duplicate directories and files from within the file explorer?
Visual Studio-CodeVisual Studio-Code Problem Overview
Ideally, I would right-click on the folder/directory or file I want to duplicate, choose "Duplicate" and, hopefully, would be asked in the same step to give the new duplicated file or directory a new name.
Looking at the current options, I couldn't find a way to do this on latest VSCode 1.19.1 (macOS):
Am I missing something? Is there other way to do this?
The more I use VSCode, the more I get used to it and, lately, I found myself barely needing to use the terminal provided in the Panel, or switching to a terminal app, for simple stuff like this.
Visual Studio-Code Solutions
Solution 1 - Visual Studio-Code
To duplicate a file within a folder.
On the explorer pane:
- right click on the file,
- press copy
- now right click on the folder, and
- press paste
- the file will be duplicated into the same folder with "...-1" or " copy" appended to the file name
Solution 2 - Visual Studio-Code
Marketplace extension File Utils:
Solution 3 - Visual Studio-Code
The "Duplicate action" extension will allow you to right click and choose duplicate as you described.
Solution 4 - Visual Studio-Code
A somewhat old issue now but as I try to avoid installing too many extensions this may be helpful to others wanting to avoid the same. Also, as there's a strong chance this is a context in which you're using a mouse/trackpad (as opposed to keyboard), the normally fantastic 'do everything' quick menu thing (or whatever Shift + CMD + P
is called) is probably not a great solution...
- Hold down
Alt
. (Note: You can actually do this during step 2 if preferred). - Drag the file onto the folder it is already in (during drag the cursor will have a green plus icon).
- Release the file where you want it to be (doesn't actually have to be the same folder).
- The file will be duplicated with the filename
{original-filename} copy.{original-extension}
. - Click on the file again.
- Hit enter/return to edit the filename.
All the above sounds much more onerous than it really is. I find it quicker than right-clicking and momentarily finding/navigating to a menu option, especially if that menu option is not a native one.
Solution 5 - Visual Studio-Code
How about the good old CTRL+C and CTRL+V?
I just tried. If you click on a file then press CTRL+C, and then CTRL+V then you get a duplicate of the file named [original name] copy.[ext]
It's a mystery, though, why the duplicate file option is still not on the right-click menu after so many years.
A little warning: doing this will remove the content of the clipboard. So if you are in the middle of a copy-paste cycle, then make sure to save the clipboard content somewhere. Yes, it's inconvenient, but until MS decides to put in this basic action in the context menu (right-click) we need to deal with it.
Solution 6 - Visual Studio-Code
CTRL+C CTRL+V F2 type new name ENTER opens in editor
Similar to above but with an extra couple of things
Solution 7 - Visual Studio-Code
Another solution, since VS Code still does not allow this in 2022:
Install the multi-command package.
Then, in your keybindings.json
add the following:
{
"key": "cmd+d",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"filesExplorer.copy",
"filesExplorer.paste"
]
},
"when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !inputFocus"
}
Afterwards, you can press CMD + D
to duplicate a file or folder.
You may want to add "renameFile"
into the sequence to directly rename the duplicate. Of course, this works just as well with ctrl
instead of cmd
.