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.

3
  • 2
    Do you mean DirectoryInfo.Create or Directory.CreateDirectory? There is no Directory.Create method. Sep 20, 2014 at 17:11
  • 3
    right click on desktop and create new folder ...can you give it 'prn' name??
    – AminM
    Sep 20, 2014 at 17:15
  • I meant Directory.CreateDirectory. Thanks for the correction.
    – Klaus Nji
    Sep 20, 2014 at 17:26

1 Answer 1

29

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

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.