Copying filenames to clipboard, and why Windows XP or earlier don't do it
Posted: (EET/GMT+2)
When I'm managing my files, I'm using Windows Explorer. But I often find myself in a situation where I'd need the full path and file name of a set of files, for example to be pasted to source code, documentation, or e-mail message. Up to Windows XP, you had to ready-made solution for this, and thus I ended writing simple console applications, that I would then place (or rather, the .EXE file's shortcut) in the Windows SentTo folder.
Then, when I would select one or more files in Windows Explorer, right-click, and then select my application form the Send To submenu, Windows would execute my program, and pass in the full path of each file selected as regular command-line parameters. Thus it would be trivial to pick them up in code, and place them in the clipboard, for example each on a line of their own.
For example in C#, you could write an application like this:
using System;
using System.Text;
using System.Windows.Forms;
namespace CopyFilenames
{
class Program
{
[STAThread]
static void Main(string[] args)
{
if (args.Length > 0)
{
StringBuilder paths = new StringBuilder();
foreach (string path in args)
{
paths.AppendLine(path);
}
Clipboard.SetText(paths.ToString());
}
}
}
}
Or, in Borland/CodeGear Delphi:
Program CopyFilenames;
{$APPTYPE CONSOLE}
Uses
Classes,
SysUtils,
Clipbrd;
Var
SL : TStringList;
I : Integer;
Begin
If (ParamCount > 0) Then Begin
SL := TStringList.Create;
Try
For I := 1 to ParamCount do Begin
SL.Add(ParamStr(I));
End;
Clipboard.AsText := Trim(SL.Text);
Finally
SL.Free;
End;
End;
End.
I've succesfully used this method since Windows NT 4.0 I believe, and even still on Windows XP. However, with Windows Vista, you don't need these kind of solutions anymore, as you can hold down the Shift key while right-clicking a file (or a set of files), and then selecting the "Copy as Path" command. Neat.
But still one question remains: why didn't Microsoft implement this quite trivial, but often essential little time saver function in Windows operating systems a long time ago? Raymond Chen's (of "The Old New Thing") article in the recent TechNet Magazine details why. Yes, they tried to do it, but it didn't work. As it often is, the more you know about a system, the more likely you are to accept its shortcomings.