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 1,918 other followers

Archive for November 8th, 2012

.NET/C#: Drives, Directories, Paths and Filenames in Windows is hard, let alone cross platform (: via: .net – Why Path.Combine doesn’t add the Path.DirectorySeparatorChar after the drive designator? – Stack Overflow)

Posted by jpluimers on 2012/11/08

Handling names of drives and paths (directories, filenames) is hard in Windows, as both C:myfile.ext and C:\myfile.ext are valid – but potentially different – filenames, C is a valid driveletter, C: and C:\ are valid – but also potentially different – directory names.

This leads into confusion as how Path.Combine behaves.

Part of the confusion comes from the meaning of the absence or presence of the leading DirectorySeparatorChar as explained by user Peter van der Heijden:

C:filename is a valid path and is different from C:\filename. C:filename is the file filename in the current directory on the C: drive whereas C:\filename is the file filename in the root of that drive. Apparently they wanted to keep the functionality of refering to the current directory on some drive.

This behaviour is described here in MSDN

Another oddity is that Path.Combine will only use the drive portion of the left argument when the right argument contains an absolute path.

If you understand the above, then dealing with cross platform directory and path separators, spaces in filenames and UNC path names are peanuts (:

–jeroen

via: .net – Why Path.Combine doesn’t add the Path.DirectorySeparatorChar after the drive designator? – Stack Overflow.

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »

 
%d bloggers like this: