The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,514 other followers

File extension parameters do include a dot

Posted by jpluimers on 2011/07/20

This is from a long time ago, but still fun:

Sometimes simple things in life are hard do remember.

For instance, I always forgot if a file extension parameter should have a dot in it or not.

Normally it should!

But for clearing an extension, you should use a blank string.

Be aware though that empty extensions look differently depending where in the process you look at them:

C# example:

using System;
using System.IO;
public class Test
        public static void Main()
                string extensionLess = Path.ChangeExtension(@"C:\mydir\", "");
                string extension = Path.GetExtension(extensionLess);



Delphi example:

program Demo;
  extensionLess: string;
  extension: string;
  extensionLess := ChangeFileExt('C:\mydir\', '');
  extension := ExtractFileExt(extensionLess);



Don’t you love differences in your platforms :)


4 Responses to “File extension parameters do include a dot”

  1. petermoor said

    Interesting indeed…

    Maybe, if file systems would be re-designed completely from scratch, the extension (or let’s say “file type”) should be a completely different field from its name. When you think about it, it’s actually quite silly that we have to parse a name to retrieve the file type, completely based on conventions. And it makes room for problems like this one.

    • jpluimers said

      Actually, back in the DOS 8.3, era it was a field,and not a convention ;-)

      And sometimes the file extensions isn’t all there is; for instance an .xml file can be just XML, but add a [?mso-application progid=”Excel.Sheet”?] (replace [] by angle brackets) in the second line, and the Windows Explorer happily opens it using Excel.


  2. Pawel said

    Interesting. Shouldn’t the output from the C# example still have two lines?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: