leeand00
leeand00

Reputation: 26402

Easier way to copy the path to a file or directory to the clipboard in visual studio?

To accomplish this I've been right-clicking the file or directory and then selecting Show in Windows Explorer, and then copying the path out of the address bar.

Is there an add-on or macro that can make this task easier?

I'm aware that you can drag a file from Solution Explorer into the editor and it will write out the path, but when doing web development I don't always want the server path, sometimes I want the local path.

Upvotes: 16

Views: 12583

Answers (6)

Raphael Pinel
Raphael Pinel

Reputation: 2820

You can right click at these 2 places:

  • on the tab of the opened file at the top of the screen
  • on the file name in the file explorer (usually on the left).

The keyboard shortcuts are the same in both places

There are 2 options:

  • Copy Path. Keyboard shortcut Opt Cmd C on Mac
  • Copy Relative Rath. Keyboard shortcut Shift Opt Cmd C on Mac

Screenshot of context menu in top tab bar

Screenshot of context menu in file explorer

This was already mentioned in other answers, but I wanted to give it more visibility, as this is the simplest way in my opinion.

Upvotes: 0

maru
maru

Reputation: 206

Tools > Options > Environment > Keyboard

You can set your own shortcut keys for anything. The two that are most relevant to this post are "File.CopyFullPath" and "File.CopyRelativePath". I created my shortcut to just be used in "Text Editor" and it has worked great.

This was asked for VS2010 and I'm using VS2019, so it is an old question, but still relevant. I knew about the file header right click menu, but for some reason I didn't think about the shortcut keys until I read this question. Posting in case this results in a quicker fix for anyone else.

Upvotes: 1

KeyC0de
KeyC0de

Reputation: 5277

The CTRL+C doesn't work for me on MSVS 2017. Use the copy as path extension here. Then right click on file in solution explorer -> Copy as path (or assign a shortcut). I find that it works very well.

Upvotes: 0

Andrii Radchenko
Andrii Radchenko

Reputation: 11

I've found one more option of how to solve it without plugins (for VS 2015 and above; not certain about previous versions) Go to "Tools" -> "Customize..." -> "Commands" tab. Choose "Context menu:" and "Project and Solution Context Menus | Item" and you can add any existing Command.

In order to copy path, choose Category "File" and "Copy Full Path" command. Will add button only for files in Solution Explorer. This works for projects as well but you should choose "Project and Solution Context Menus | Project" (copy path of .vcxproj file).

It doesn't work for solutions and I don't understand actually why.

Upvotes: 1

capawaky
capawaky

Reputation: 127

You can just select the file in the 'Solution Explorer' file list and hit CTRL+C. It automatically copies the file path to your clipboard.

Upvotes: 10

MadBender
MadBender

Reputation: 1458

Look at PowerCommands extension

http://visualstudiogallery.msdn.microsoft.com/e5f41ad9-4edc-4912-bca3-91147db95b99?SRC=Home

Among others, it contains "Copy Path" command for files and folders

UPD: Also, another option: right-click the tab of open document and there will be "Copy Full Path" command. It's built-in, no extensions needed

Upvotes: 11

Related Questions