Windows Tips: Keep Your Data Folders in Date Order Automatically

I read the tip in your June column about creating a new folder from the right-click menu. Is there any way to name a new folder with the current date simply by clicking the right mouse button? I mark my customers' folders with the date on which they bring in files to be printed. So automatically naming folders by their date of creation could shave my workload.

Daryl Piso, Fort Lauderdale, Florida

Date-based folder names are great for storing digital photos, e-mail messages, and many other kinds of files. Fortunately, you can customize menus in Windows 2000 and XP to let you create a folder named with the current date, using just two clicks of your mouse.

Start by making sure that the date format you use is valid for your folder names. For example, a date like 10/31/05 is verboten because Windows doesn't allow slashes in file and folder names. You'll probably want the folders arranged in chronological order even when sorted by name, so list the year first in the name. (If the month comes first, any files you create in October, November, and December will immediately follow the ones you made in January.) A date format such as 2005-10-31 for your folder names will keep things nice and sorted.

To have Windows use this date format all the time, open the Regional Options (or Regional and Language Options) control panel: Choose Start, Run, type control intl.cpl, and press <Enter>. In Windows XP, select the Regional Options tab and click Customize. In both versions, click the Date tab and choose yyyy-MM-dd from the 'Short date format' drop-down list (see Figure 1

Figure 1: Choosing the right format sorts date folder names chronologically.
). Then click OK as many times as necessary to close the dialog boxes.

Next, add the command that will create a folder with this date format: Press <Win>-E to open Windows Explorer, choose Tools, Folder Options, and in the Folder Options dialog box, click File Types. In the 'Registered file types' list, scroll to and select File Folder. Click Advanced to open the Edit File Type dialog box, and then click the New button. For 'Action', type the words that you want to appear on your context menu (such as New Folder With Today's Date). For 'Application used to perform action', type cmd.exe /c md "%1\%%DATE%%", as shown in Figure 2

Figure 2: This command line adds a date-based folder-making feature to your right-click menu.
. Make sure that you type the command--instead of pasting in a copy--so it will contain straight double quotation marks (") rather than opening or closing curly double-quotes. Click OK twice and then Close to return to Explorer.

(A bug in Windows XP's Edit File Type dialog box can cause aberrant behavior when you double-click a folder. The fix entails making a minor Registry tweak. See my August Windows Tips column for instructions.)

Now when you right-click a folder icon in Explorer, you'll see an option labeled 'New Folder With Today's Date' (or whatever you named your command; see Figure 3

Figure 3: Just right-click a folder to create a subfolder named with today's date.
). Click it to create a new folder, named for the current date, inside the folder whose icon you right-clicked.

You can't create two folders with the same name inside a single parent folder, so use it only once per day per folder.

More Date Options

Unfortunately, Windows 2000 insists on putting the day of the week ('Mon', 'Tue', and so on) in the folder name, which prevents the folders from appearing in chronological order when you sort them by name. One workaround is to choose View, Arrange Icons by, Modified, but if this is too many extra clicks for you, or if you just don't want to change your regional settings to force all dates to have the more orderly format, you can create a batch file (for either 2000 or XP) that gives you more options for customizing the date format.

To get started, launch Notepad or another text editor and enter the text shown in Figure 4

Figure 4: Create and customize this batch file in Notepad to give yourself more format options for your date folders.
. This batch file contains techniques from batch master Timo Salmi, a professor at the University of Vaasa, Finland; to see many examples of his batch techniques, download the file

The batch file establishes the period, slash, hyphen, and space as delimiters (characters that separate the data you're after). It then looks at the contents of the '%DATE%' variable--that is, the current date--and puts the second, third, and fourth items from the date (as determined by the delimiters) into the variables '%%f', '%%g', and '%%h'. These represent the month, day, and year. The third line of the file stores the date variables in year-day-month order, separated by hyphens, within the variable 'today_'. The fifth line combines that variable with the make directory ('md') command to create a folder that has the desired date name.

If you prefer folder names separated by periods (as in '2005.10.31'), replace the two hyphens in the third line of the batch file with periods. Or delete the hyphens in that line altogether to produce a folder name such as '20051031'. Rearrange the '%%f', '%%g', and '%%h' variables in the third line any way you want to get the desired order of month, day, and year.

You may also have to change the batch file to match the settings you selected in the regional settings. For example, if you chose the yyyy-MM-dd format, you'll have to change the '2-4' in the second line of the batch file to 1-3 in order to get the right parts of the date to appear. In addition, you may need to reorder the variable elements as described in the previous paragraph.

When you're done, save the batch file with a name like datefolder.bat. Place it wherever you store such files--say, in a folder named 'c:\batch'. Then return to the Edit File Type dialog box for File Folders and click New as explained earlier. But this time type the following command in the 'Application used to perform action' box: cmd.exe /c c:\batch\datefolder.bat "%1" (your path and batch file name may differ). Click OK twice, and then click Close to return to Explorer.

If you made a mistake while entering text in the New Action dialog box, you have to use the Registry Editor to fix it. For safety's sake, create a backup of your Registry (click here for instructions). Choose Start, Run, type regedit, and press <Enter>. In the tree pane on the left, navigate to and double-click HKEY_CLASSES_ROOT\Directory\shell. Select the folder with the name of the command you just added (in our example, 'New_Folder_With_Today's_Date'), and double-click the (Default) icon in the right pane to open the command line in the Edit String dialog box. Make your correction, or delete your custom command altogether by closing the dialog box, right-clicking the folder in the left pane, and selecting Delete, Yes; for more details, see "Resort to Regedit" in last December's column.

1 2 Page 1
Page 1 of 2
Shop Tech Products at Amazon