Second path fragment must not be a drive or UNC name exception

M

Mike

Hi! On some Windows 7 machines I am getting the following error when I
execute this code to enumerate all named pipes on a PC:

string[] pipeNames = null;
try
{
pipeNames = System.IO.Directory.GetFiles(@"\\.\pipe\");
}
catch (Exception ex)
{
}

ERROR:
System.ArgumentException: Second path fragment must not be a drive or UNC
name.

Parameter name: path2

at System.IO.Path.InternalCombine(String path1, String path2)

at System.IO.Directory.InternalGetFileDirectoryNames(String path, String
userPathOriginal, String searchPattern, Boolean includeFiles, Boolean
includeDirs, SearchOption searchOption)

at System.IO.Directory.GetFiles(String path, String searchPattern,
SearchOption searchOption)

at System.IO.Directory.GetFiles(String path)

I can not put my finger on what would cause some Windows 7 PC's crash and
some work perfectly fine. It also works fine on Vista

Any ideas/suggestions/help is greatly appreciated.
 
J

Jeff Johnson

I was having the same problem, but without having named pipes involved.
The cause
turned out to be (IMHO) obscure: I was escaping the dot in the
searchPattern:

WRONG:
try { exFiles = new ArrayList(Directory.GetFiles(exDirectory,
@"\.xml")); }

RIGHT:
try { exFiles = new ArrayList(Directory.GetFiles(exDirectory, @".xml")); }

Duh me, but also Duh Microsoft.

Directory.GetFiles() does not use RegEx in the search pattern*, nor does it
even suggest that it does, so I don't see where it's an issue of "Duh
Microsoft" in any way, shape, or form.


*Which is what I assume you were thinking, otherwise I can't find a
plausible reason why you would feel the need to escape a period.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top