How can I check if a directory Test
exists under the path C:\\mypath\\is\\here
?
String[] getAllSubDirs = Directory.GetDirectories(directory, Match, SearchOption.AllDirectories);
foreach (String subDir in getAllSubDirs)
{
if (!subDir.Contains("test"))
{
ListViewItem list = new ListViewItem(subDir);
list.SubItems.Add("N/A");
listView.Items.Add(list);
listView.EnsureVisible(list.Index);
}
}
I want to print out those directories that do not have a folder named Test
present.
Instead of
!subDir.Contains("test")
do
!Directory.Exists(Path.Combine(subDir, "Test"))
you can use
Directory.Exists(Path.Combine(subDir, "test"))
or if you just know the full path:
Directory.Exists("C:\mypath\is\here\test")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.