Saturday, January 16, 2010

Formatting Windoes Explorer Detail Columns to Fit Contents

If you use Microsoft Excel, you may have discovered a shortcut that is undocumented, so far as I know, that allows you to auto-fit a single worksheet column to fit its contents by double-clicking on the divider between the column and its right hand neighbor.

Today, I discovered that, not too surprisingly, the same shortcut works in the Windows Explorer. Since I work in the Detail view most of the time, I am always adjusting the widths of one or another of its columns, depending on the information that is currently of most interest. Just for fun, I decided to test the double-click. Sure enough, the width adjusted, exactly as it would in Microsoft Excel!

In both cases, you must double-click on the border at the top of the window. In Excel, this is the part where you see the column labels, A, B. C ... etc.

Likewise, in the Windows Explorer, you must double-click on the area that contains its column labels, File, Size, Type, Date Modified, ... etc.

This new knowledge will save me lots of time!

Friday, January 8, 2010

To Copy A Directory Tree, Without Copying the Files

For the first time in a long while, I just needed to duplicate the structure of a directory tree, without copying the files.

The Problem

Duplicate the structure of the directories that hold my program source code, so that I can move the archives of completed projects out of the active development directories, which are backed up nightly to an offsite location, while keeping them organized as they currently are in the development directories.

The Solution

I began by starting a conventional copy, using the Windows Explorer. As it got underway, it occurred to me that there had to be a more efficient way. A quick Google search yielded instant results.

The search term was straightforward, "copy directory structure only."

The command that got the job done, in less than a minute, is equally straightforward, as shown in Listing 1, which I copied and pasted from my command prompt window.

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
 
C:\Common_Data\WinZip_archives\code_libs>XCOPY "C:\Documents and Settings\David\
My Documents\Programming" /T /E
 
C:\Common_Data\WinZip_archives\code_libs>
 
Listing 1 - The command above, XCOPY "C:\Documents and Settings\David\My Documents\Programming" /T /E, leverages the sparsely documented T switch of the faithful XCOPY command, which has been a stalwart friend since at least 1989.

More Shortcuts

OK, so I cheated.

  • I used a shell extension to open my command prompt window with the target directory already made current.
  • I used the Windows Clipboard to get the name of the source directory right the first time.

This second shortcut is especially noteworthy, because it calls attention to another sparsely documented feature of Windows, which is that pretty much anything that you can highlight can be copied, using the CTRL-C keyboard shortcut.

Among other things, this means that you can copy from any of the following locations.

  • The address bar of a Windows Explorer window.
  • The file name text box of a file property sheet.
  • Any other text box.
  • Some other text on property sheets. Among others, I've had success with the following.
    • File create, modify, and access dates on file property sheets.
    • File sizes, also on file property sheets.
    • Version strings, from the Version page of the property sheet for an EXE or DLL file.

If you need text from almost anywhere in a Microsoft Windows application, try to highlight it. If it's text on the flat surface of a dialog box, try dragging the mouse across it. If you can highlight it, a quick CTRL-C  puts it into the clipboard.

For Geeks Only - Why This Works

Although it isn't obvious, selectable text lives in a Text Box control. It isn't obvious that it's a control, because of the way its properties were set at design time.

  • Border is set to None.
  • Background is set to Transparent, or its color is set to be the same as that of the dialog box surface.
  • 3D effects are off.

How these settings are applied depends on the development environment, but all can be set in any environment that lets you build custom dialog boxes and other types of forms. Among others, this includes VBA (hosted in Microsoft Access, Word, Excel, PowerPoint, and Outlook, among others), Visual Basic (classic versions 1 through 6), VB.NET, and C#. This also includes the WinBatch dialog editor, and probably numerous others.