Klaus Nji
Klaus Nji

Reputation: 18847

Directory.CreateDirectory could not find a part of path c:\

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.

Upvotes: 11

Views: 2747

Answers (1)

AminM
AminM

Reputation: 1814

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

Upvotes: 30

Related Questions