devxlogo

Copy Filenames to a Clipboard

Copy Filenames to a Clipboard

File hierarchies are becoming more complex and file paths longer as the capacity of hard drives increases. There are still many occasions, however, when you can’t browse to identify a file to be used?for example, when entering a constant in VB source. Normally, there is no alternative but to type in the path?this can be both tiresome and error-prone.

The solution: Create a new Standard EXE project, delete the default form (Form1), and add a module (Module1 by default). Type this code into Module1:

Sub Main()	Clipboard.SetText Command$End Sub

Under Project | Project Properties, set the Startup Object to Sub Main. Give the project a suitable name (for example, filename) and create the executable (in this case, filename.exe). Create a shortcut to the executable on your desktop. When the name of file is required, browse using Explorer or My Computer. Drag the file and drop it onto the filename shortcut. The full path of the file is now on the clipboard and you can paste it as necessary.

This works because dropping an object onto a program or its shortcut starts it with the name of the object in the command line. The program merely reads the command line and puts it onto the clipboard.

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist