2010-09-13

Name Log Files in a Consistent Format

I expect developers to program like I do, which didn't happen this week.

The task is to concatenate log files in a folder into a single file to import into a database. The Windows command to do the job is for /f %a in ('dir /b *.csv') do type %a >> dest.csv. (dir /b lists entries in a folder without any heading.) While testing using echo in place of type, I noticed that due to the way dir sorts file, the script would concatenate log files in this order: Log-02.csv, Log-03.csv, ..., Log.csv i.e. the first log file last. This order seems to correspond with the characters in the ASCII table.

(Aside: Windows Explorer lists Log.csv first because Explorer doesn't use ASCII sort order.)

Of course, just to get the job done, the work-around is to rename Log.csv to Log-01.csv before running the script.

It threw me that developers wouldn't name log files consistently.

2010-09-10

SetLocal EnableDelayedExpansion in CMD Scripts

In a Windows CMD for loop, variables within the loop aren't, by default, resolved into a value for every iteration of the loop. Here's a script that should list all files in a folder.

@echo off
for /f %%a in (*) do (
  set test=%%a
  echo %test%
)

However, when you run the script, only the first file found is output (the variable test is only set in the first iteration of the loop). Turns out that I'm the n'th generation of CMD programmers to trip over this issue. It seems that CMD only processes the for (...) statement once, so the variable test is only set once. To get CMD to reprocess your variable in each iteration, put your code into a setlocal EnableDelayedExpansion ... endlocal block and delimit with exclamation marks any variables that CMD should reprocess in each iteration of the loop (hence the unintuitive name of the block).

@echo off
setlocal EnableDelayedExpansion
for %%a in (*) do (
  set test=%%a
  echo test=!test!
)
endlocal

I couldn't find an official MS documentation of EnableDelayedExpansion or the use exclamation marks for variables.

2010-08-01

Restoring Standard Outlook Forms

If you can't see any of the standard Outlook forms, there are two solutions:

  • Clear your Outlook forms cache:
    1. In Outlook, select menu item Tools, Options.
    2. In Options dialog, select Other tab.
    3. In Other tab, press Advanced Options… button.
    4. In Advanced Options dialog, press Custom Forms… button.
    5. In Custom Forms tab, press Manage Forms… button.
    6. In Forms Manager dialog, press Clear Cache button, then press the Close button.
    7. Close all the Option dialogs and try accessing the form again.
  • If the above doesn't work, a more risky solution is to get Outlook to recreate its cache file:
    1. Exit Outlook.
    2. Use Windows Explorer to open the temporary forms folder. On my WinXP PC, the path is C:\Documents and Settings\<user>\Local Settings\Application Data\Microsoft\FORMS.
    3. Rename or delete the file FRMCACHE.DAT.
    4. Start Outlook again.

See Also

2010-07-29

Fixing Broken Image Links in Outlook

If Outlook stops displaying images embedded in HTML e-mail, the fix is to delete files in its temporary file folder. On my WinXP computer, that temporary folder is: C:\Documents and Settings\<user>>\Local Settings\Temporary Internet Files\OLK<random>.

To find the location of Outlook's temporary folder on your PC, open an e-mail message with a Word or Excel attachment, open the attachment and save it. The default location displayed in the application's Save dialog is the location of the temporary folder. This technique works for Word or Excel but other applications may instead show the last folder you used.

For the motivated, the temporary folder's path is stored in the registry in this key: HKCU\Software\Microsoft\Office\<Office version>\Outlook\Security\OutlookSecureTempFolder.

Notes:

  • You can't see that folder using Windows Explorer by browsing the parent folder, C:\Documents and Settings\<user>>\Local Settings\Temporary Internet Files. Instead, to see the contnts of the folder, you have to type in its path in the Explorer's address bar.
  • If you use a CMD console, you can list that folder using the dir command.
  • If you make a shortcut to that folder and try to use the shortcut, Windows shows this warning: This page has an unspecified potential security risk..

See Also