How to copy file path to clipboard?

Is there a way to copy the currently selected filename, including the path, to the clipboard? Ideally this would be through the right-click menu.

Some degree of flexibility would be useful, like the ability to copy just the filename, path+filename, filename minus extension, etc. This isn't essential, though, as long as it can copy the path+filename.

The solution must be compatible with Windows XP, Windows Vista and Windows 7.


Solution 1:

Use CopyFilenames

or

Copy Filenames to Clipboard Utility

Windows XP has no way to copy a list of filenames to the clipboard (this has changed in later versions of Windows, starting with Vista). A Microsoft Knowledge Base article suggests writing a small *.bat file that runs the DIR command, collects its output into a file, prints that file, then deletes it. This may be convenient some times, but it would be more useful to be able to select a list of files, and have the names of them put on the clipboard. Then you could paste them wherever you needed them.

So here's a utility to do that. You have to do a bit of work yourself - but not much - to install it. Here are the instructions:

  1. Download the executable. It's only 20 KB, so it should take only seconds even if you're using dial-up access. Save it wherever you want it to reside on your system.
  2. Create a Shortcut in "Go To"

    1. Go to the "Send To" folder under your name in \Windows\Profiles in Windows Explorer (or maybe XP Home puts that directory under the Settings folder, I can't remember).
    2. Right-click in the right-hand pane, where the filenames are. Select "New|Shortcut".
    3. The "Create Shortcut" wizard will appear. On the first page, type in the path to the executable, or use the "Browse..." button to find it. Click ""Next".
    4. On the second page, type in a name for your new menu option. I used "File Names to Clipboard", but pick whatever will be meaningful to you. Click "Finish"

That's it; you've got it installed. Now select one or more files, right-click, and move your mouse pointer to "Send To". A submenu will appear which will include your new command. Choose that command, and a list of the files you've selected, sorted in ascending order, will be on the clipboard.

Source: http://members.cox.net/slatteryt/FNtoClip.html

Solution 2:

Beginning with Vista you can just Shift+Right click on the file in Explorer and select "Copy as path":

        "Copy as path" context menu entry in Windows 7

This even works for multiple files, which are put into the clipboard one per line.

In Windows 8 this is exposed in the Explorer ribbon:

        "Copy path" button in the Windows 8 Explorer ribbon on the Home tab

Solution 3:

I use the MS 'Send to X' PowerToy available as part of the Windows 95 PowerToys set (MS download link).
This adds 'Clipboard as Name' (as well as 'Clipboard as Contents' and a few other options) to the right-click 'Send To' menu.
The easiest way to install is to extract the downloaded W95powertoy.exe with a Zip utility, rightclick 'SENDTOX.INF' and select 'Install'. You can remove any unwanted items from the 'Send To' menu by opening it in Explorer.

Works fine on Windows XP - not on Windows 7, but as noted by Johannes, you can use 'Shift + right-click' instead.

Solution 4:

I use Ninotech Path Copy. Their website is dead, but it can be found here.

There's 14 different possibilities for copying file names, 5 of which you can fully customize.

Solution 5:

Here is my open source solution and also free, if you consider Windows free :)

Create a batch file, say, listfiles.bat. Put either of the following into the file:

FILENAMES

set mylist=myfilelist.txt
set tempfile=tmp.txt
set diroptions=/a /b

set fullpath=%1
for %%i in (%fullpath%) do set path=%%~dpi
cd %path%

if exist %mylist% del %mylist%
if exist %tempfile% del %tempfile%

dir %diroptions% > "%path%%mylist%"

for /f "usebackq delims=" %%a in ("%mylist%") do (
if not "%%a"=="%mylist%" (
echo %%a >> %tempfile%
)
)

del %mylist%
ren %tempfile% %mylist%

PATH AND FILENAMES

set mylist=myfileandpathlist.txt
set tempfile=tmp.txt
set diroptions=/a /b /s

set fullpath=%1
for %%i in (%fullpath%) do set path=%%~dpi
cd %path%

if exist %mylist% del %mylist%
if exist %tempfile% del %tempfile%

dir %diroptions% > "%path%%mylist%"

for /f "usebackq delims=" %%a in ("%mylist%") do (
if not "%%a"=="%path%%mylist%" (
echo %%a >> %tempfile%
)
)

del %mylist%
ren %tempfile% %mylist%

Now create a shortcut to that file in C:\Documents and Settings\<username>\SendTo directory. Go to the directory you want to get a list of files from. Right click on any file and choose Send To -> Shortcut to listfiles.bat. The list of files will be written to myfilelist.txt or myfileandpathlist.txt depending on your choice. Obviously there is nothing stopping you from having shortcuts to both batch files in the SendTo directory.

For the full list of dir switches type dir /? on the command line or visit this website.