سلام
دوستان من چطور مي تونم بفهمم كه مثلا داخل درايو c پوشه example موجود است يا نه ؟
Printable View
سلام
دوستان من چطور مي تونم بفهمم كه مثلا داخل درايو c پوشه example موجود است يا نه ؟
از for each استفاده کن در این کد من سعی کردم پوشه ای به نام BarbodData را در درایو C پیدا کنم.
For Each fa As String In My.Computer.FileSystem.GetDirectories("c:/")
If fa = "c:\BarbodData" Then
MsgBox("فولدر موجود بود")
End If
Next
این روش ساده تر و سریعتر است :
If IO.Directory.Exists("C:\Example") Then MsgBox("Folder Found")
اگه بخوایم تمامی زیر شاخه های درایو c رو هم بگردیم کدش چی میشه؟
ممنون
شما باید از تابع بازگشتی استفاده کنید(خود دات نت برای جستجو تابع داره اما من تا حالا کارکرد ازش ندیدم...) :
Public Sub FindFolder(ByVal path As String, ByVal name As String, ByVal array As ArrayList, Optional ByVal searchsub As Boolean = False, Optional ByVal Attributes As IO.FileAttributes = IO.FileAttributes.Directory)
On Error Resume Next
Dim dirinfo As New IO.DirectoryInfo(path)
For Each dir As IO.DirectoryInfo In dirinfo.GetDirectories()
Application.DoEvents()
If dir.Attributes = Attributes And IO.Directory.Exists(dir.FullName & "\" & name) Then
array.Add(New IO.DirectoryInfo(dir.FullName & "\" & name))
End If
Next
If searchsub Then
For Each dir As IO.DirectoryInfo In dirinfo.GetDirectories()
Application.DoEvents()
FindFolder(dir.FullName, name, array, searchsub, Attributes)
Next
End If
End Sub