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

A menu utility to copy the name or path of a file or folder

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 Cloud-based document-processing
Gnostice StarDocs

Gnostice StarDocs is a scalable, fault-tolerant document-processing server solution, designed to be the central go-to place for all kinds of electronic document-processing work. StarDocs includes a web application (as seen at stardocs.gnostice.com) that frees your end-users from the need to have format-specific software to merge, split, redact, convert, edit, and sign documents - all they need is a network connection and a HTML5 browser. StarDocs provides a REST-based API that your developers can use to add document-processing functions to a variety of software applications. As the REST API is platform agnostic, your developers can write software on a wide variety of platforms - from desktop to mobile devices to Web services in any development language. To get them started quickly, StarDocs is supported by language-specific native SDK. StarDocs document server has load-balancing built-in and is designed to be scalable across enterprise Intranets and the Internet. StarDocs is available as packaged software for on-premise hosting and also as a subscription-based cloud service.

Our Delphi/C++Builder developer tools
XtremeDocumentStudio Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

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.

Our .NET Developer Tools
XtremeDocumentStudio .NET

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

PDFOne .NET

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

Our Java developer tools
XtremeDocumentStudio (for Java)

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

PDFOne (for Java)

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

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-2015 Gnostice Information Technologies Private Limited. All rights reserved.