11

Why does Directory.CreateDirectory throw a DirectoryNotFoundException when attempting to create the following path?

"c:\\temp\\aips\\data\\prn"

with message indicating it could not find a part of the path "c:\".

Yet, if passed the following path "c:\\temp\\aips\\data\\power", it returns successfully.

The paths are copied directly from the Visual Studio debugger hence the back slash delimiters.

On my system, the folder c:\temp\aips\data already exists.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Klaus Nji
  • 18,107
  • 29
  • 105
  • 185

1 Answers1

28

As Scott Chamberlain says in a comment prn is one of the reserved device names and it points to the print device in DOS.

The specified device name is invalid

so change your path to another name and don't use the following reserved names for the name of a file:

CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9

Community
  • 1
  • 1
AminM
  • 1,658
  • 4
  • 32
  • 48
  • 4
    `com#`, `lpt#`, `aux`, `con`, and `nul` are other [reserved device names](http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#naming_conventions). – Scott Chamberlain Sep 20 '14 at 17:21
  • 3
    Thanks for the response. Definitely not intuitive from the exception message. – Klaus Nji Sep 20 '14 at 17:28