Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 418
Klaus Nji Avatar asked Sep 20 '14 17:09

Klaus Nji


People also ask

Could not find a part of the path in Visual Studio?

This will happen when TFS has some changes staged that no longer exist on the file system. For instance, if you add some files in Visual Studio (which adds them to the changes list), delete them directly from the file system, then attempt to check in the changes, it will complain that it could not find the file(s).

Could not find a part of the path TFS?

The error you have is mainly caused when you're trying to check in files which is no longer exist on the machine. To resolve it, go to Source Control Explorer -> select these missing files -> Undo Pending Changes. Or you can just left these files in the Excluded Changes list to not checking them.

Could not find a part of the path in VB net?

If the error message says that it couldn't find part of the path then it couldn't find part of the path. You cannot create a folder and a file at the same time. You can only create a file in a folder that already exists. If the folder doesn't exist then you must create it first, then create the file.


1 Answers

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

like image 104
AminM Avatar answered Oct 21 '22 05:10

AminM