PDFOne .NET XtremeDocumentStudio .NET PDFOne (for Java) XtremeDocumentStudio Delphi eDocEngine VCL PDFtoolkit VCL

Copy File Path And Name Using Windows Explorer Context Menu Extensions

Using some registry tricks and clipboard utilities. Full source code included.
By V. Subhash

If you work in a big company or if your files are scattered over several server shares, then you may often find yourself copying the path or the name of a file in Windows Explorer. The steps involved are simple but it may seem cumbersome when you do it several times a day.

If I am right, then you will be happy to know that you can use some context menu (shortcut menu) options to reduce the number of steps. In Windows XP, there are no such menu options. In Windows Vista and Windows 7, you can hold the SHIFT key and then right-click on a file to get a "Copy as path" context menu option. Unfortunately, this option has some limitations. Here are some:

  1. Requires the use of the keyboard (for pressing the august SHIFT key)
  2. Remains only temporarily
  3. Double-quotes the path
  4. Does not translate the path for shortcuts

At the bottom of this page, you can download two simple utilities that will provide more user-friendly context menu options. I had originally created them for my colleagues. I have seen the menu extensions working in Windows XP and Windows 7. I expect the extensions to work in Windows Vista also. However, these utilities were a personal project and are not endorsed or supported by Gnostice. For this reason, I have decided to provide full source code so that you can compile the utilities yourself. Test them. If it works, use them.

When the utilities are installed properly, Windows Explorer will get four new context menu options. Two of the menu options will be available for files and the other two will be for folders. These options will allow you to copy the path or the name of the file or folder that you have right-clicked.

Windows Explorer Context Menu Options for Files

Windows Explorer Context Menu Options for Folders

How Do They Work

The download zip file contains two folders. Each folder contains a small application written in Visual Basic 6, a .reg installer file, a .reg uninstaller file, and a readme text file.

The first utility is simply called Copy Pathname (arg2cp.exe). It copies path of the selected file or folder to clipboard. The second utility is called Copy Filename (arg2cn.exe). It copies the name of the selected file or folder to the clipboard. These applications are meant to be invoked by Windows Explorer. If you try to invoke them independently, you will get nothing but an error message.

The .reg files are used in place of regular installation and uninstallation programs. The registry files create certain entries in the Windows Registry store. These entries cause Windows Explorer to provide the custom context menu options displayed above. When a user right-clicks a file or folder and selects one of the menu options, Windows Explorer will send the full path of the file or folder to the application (either arg2cp.exe or arg2cn.exe) specified by the relevant registry entry. The application processes the file/folder path information and copies the processed information to the clipboard.

Here are the contents of the .reg file installer of the first utility.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\Shell\Copy File Path\Command]
@="\"C:\\Program Files\\Copy Pathname\\arg2cp.exe\" \"%1\""

[HKEY_CLASSES_ROOT\Directory\Shell\Copy Folder Path\Command]
@="\"C:\\Program Files\\Copy Pathname\\arg2cp.exe\" \"%1\""

And, here are the contents of the .reg file installer of the second utility, which copies the name of the selected file or folder.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\Shell\Copy File Name\Command]
@="\"C:\\Program Files\\Copy Filename\\arg2cn.exe\" \"%1\""

[HKEY_CLASSES_ROOT\Directory\Shell\Copy Folder Name\Command]
@="\"C:\\Program Files\\Copy Filename\\arg2cn.exe\" \"%1\""

You can copy these registry entries to Notepad and save the file with a .reg extension. You can use that file as your installer. Now, here is the VB6 source code for the arg2cp.exe.

Attribute VB_Name = "Module1"
Sub main()
  Dim strPathname As String

  strPathname = Command
  strPathname = Right(Command, Len(Command) - 1)
  strPathname = Left(strPathname, Len(Command) - 2)

  Clipboard.Clear
  Clipboard.SetText (strPathname)
End Sub

Here is the VB6 source code for the arg2cn.exe.

Attribute VB_Name = "Module1"
Sub Main()
  Dim strPathname As String
  strPathname = Command

  strPathname = Right(Command, Len(Command) - 1)
  strPathname = Left(strPathname, Len(Command) - 2)
  strPathname = Right(strPathname, Len(strPathname) - InStrRev(strPathname, "\"))
  
  Clipboard.Clear
  Clipboard.SetText (strPathname)
End Sub

There is no error-checking code because I trust Windows Explorer to pass file path information without any errors.

How To Install

How To Uninstall

To uninstall one of these context menu extensions, navigate to the C:\Program Files\Copy Pathname or the C:\Program Files\Copy Filename folder in Windows Explorer and run the Uninstall_Copy_Pathname.reg or Uninstall_Copy_Filename.reg file.

The Uninstall_Copy_Pathname.reg reg file contains the following:

Windows Registry Editor Version 5.00

[-HKEY_CLASSES_ROOT\*\Shell\Copy File Path]


[-HKEY_CLASSES_ROOT\Directory\Shell\Copy Folder Path]

The Uninstall_Copy_Filename.reg reg file contains:

Windows Registry Editor Version 5.00

[-HKEY_CLASSES_ROOT\*\Shell\Copy File Name]


[-HKEY_CLASSES_ROOT\Directory\Shell\Copy Folder Name]

These uninstaller .reg files delete the registry entries that were originally created by the installer .reg file and Windows Explorer will no longer show those additional context menu options.

Known Issues

Sometimes, you may see two redundant menu options for ZIP files. This may be because you have installed Compressed Folders utility that comes with Windows. Compressed Folders makes Windows Explorer treat ZIP files as folders. To avoid this awkwardness, you can either uninstall the menu extensions or uninstall Compressed Folders. To uninstall Compressed Folders, use the following command in the Run dialog box of the Windows Start menu.

regsvr32 /u %windir%\system32\zipfldr.dll

Uninstalling Compressed Folder has another positive side effect - your file search operations become faster as it no longer searches inside zip files! However, to open zip files in the absence of Compressed Folders, you may wish to install a freeware zip utility such as IZarc and set it as the default application for file archive formats.

If you wish to restore Compressed Folders at a later point in time, enter the following commands, one after another, in the Run dialog box.

regsvr32 %windir%\system32\zipfldr.dll
rundll32 zipfldr.dll,RegisterSendto

Update

There have been few requests for adding more features to this utility. I would rather recommend Path Copy Copy project, which has more features.

---o0O0o---

Our Free Online Document-Processing Tools
Gnostice Apps

Gnostice Apps provides several PDF document-processing services over the Web. It enables you to merge, split, convert, secure and redact PDF documents - all for FREE. All you need to access these services is a HTML5-capable browser such as the latest version of Firefox/Seamonkey or IE 11.

Our Developer Tools
eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

XtremePDFConverter VCL

A Delphi/C++Builder component to intelligently convert PDF to user-friendly Word RTF documents.

PDFOne .NET

A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

XtremeDocumentStudio .NET

Multi-format document-processing component suite for .NET developers

PDFOne (for Java™)

A Java™ PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java™ applications.

XtremeFontEngine (for Java)

Java font engine to render glyphs from Type 1, Type 2 (CFF), and TrueType fonts

Our Office Productivity Applications
Free PDF Reader

A free, fast, and portable application for viewing, printing and converting PDF documents.

Privacy | Legal | Feedback | Newsletter | Resellers © 2002-2014 Gnostice Information Technologies Private Limited. All rights reserved.

This site is best viewed on a screen with minimum resolution of 1152 x 864 pixels. Windows XP users are advised to use Microsoft ClearType Tuning for optimal experience. Also, please use the latest version of a standards-compliant browser such as Firefox, Opera, or Dragon (Chromium).