user496949
user496949

Reputation: 86085

How can I determine if a subdirectory exists in C#?

In C#, how can one determine if a subdirectory exists?

Is this neccesary when calling CreateSubDirectory?

Upvotes: 7

Views: 17095

Answers (5)

AsifQadri
AsifQadri

Reputation: 2388

if(System.IO.Directory.GetDirectories(path).Length>0)
{
//if this condition is true-->> Directory has sub-sirectories

} 

Upvotes: 9

Madhur Ahuja
Madhur Ahuja

Reputation: 22681

If the subdirectory already exists, this method does nothing.

http://msdn.microsoft.com/en-us/library/h8dtw1d6.aspx

Use Directory.Exists to check if it exists http://msdn.microsoft.com/en-us/library/system.io.directory.exists.aspx

Upvotes: 7

Cheng Chen
Cheng Chen

Reputation: 43523

System.IO.Directory.Exists

Upvotes: 1

Billy ONeal
Billy ONeal

Reputation: 106549

Use System.IO.Directory.Exists. MSDN is your friend :)

Upvotes: 2

Arsen Mkrtchyan
Arsen Mkrtchyan

Reputation: 50712

Do you need this?

if(Directory.Exists(path)) 
{
     // This path is a directory
     ProcessDirectory(path);
}

Upvotes: 3

Related Questions