Valid directory

  • Thread starter Thread starter Alan T
  • Start date Start date
A

Alan T

How do I check if the directory path is valid and exists ?

eg.
\\myserver\temp\\\\\\

c:\temp\\doc\\\\\\root1
 
Alan said:
How do I check if the directory path is valid and exists ?

eg.
\\myserver\temp\\\\\\

c:\temp\\doc\\\\\\root1



System.IO.Directory.Exists(@"c:\temp");


cheers
 
I just wonder
c:\temp\\doc\\\root1\\\

it gives me that is valid directory but I need to get rid of the extra '\'s
 
Sorry, I don't follow the article if it helps in my problem.

Is there a way to get rid of the extra '\' in the directory string?
 
Hi Alan,

The article explains how to do string manipulation

Basically, if you have a string of several \ where there should be only 1
you can do it like this

string s = @"c:\windows\\microsoft.net\\\framework\\\";

while (s.IndexOf(@"\\") > -1)
s = s.Replace(@"\\", @"\");

The @ means treat \ as a backslash, not as an escape character
 

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

Back
Top