Thursday, March 12, 2009

Beward of tilde characters in file and directory names

I work on an application that occasionally goes across the network to look for files. I had written some code that used the GetFiles and GetDirectories calls from My.Computer.FileSystem. One of our test-beds was a remote computer (going across the public internet, rather than within a company intranet). The calls to GetFiles and GetDirectories using the SearchAllSubDirectories option were agonizingly slow on some networks, but not all.

I tried many different workarounds (including writing my own recursive GetDirectories on the theory that something was wrong in the Microsoft implementation). None of them worked until I took a deep breath and made a long list of things to try (many of them actually just data-gathering under different configurations).

Luckily, the first item on my list fixed the problem. I had been using a tilde character ('~') to help directories and files sort in a certain order. I remembered that the "shortened file name" workaround in Windows used a tilde to generate "intermediate" filenames for older applications that used fixed size buffers for 8.3 filenames.

I changed the tilde to an equal sign and the problem went away.

No comments: