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

1

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.

Coeternal answered 20/9, 2014 at 17:3 Comment(3)
Do you mean DirectoryInfo.Create or Directory.CreateDirectory? There is no Directory.Create method.Alden
right click on desktop and create new folder ...can you give it 'prn' name??Aurea
I meant Directory.CreateDirectory. Thanks for the correction.Coeternal
A
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

Aurea answered 20/9, 2014 at 17:13 Comment(2)
com#, lpt#, aux, con, and nul are other reserved device names.Kassi
Thanks for the response. Definitely not intuitive from the exception message.Coeternal

© 2022 - 2024 — McMap. All rights reserved.