DirectoryExists on 1st 4 chars

  • Thread starter Thread starter David C
  • Start date Start date
D

David C

We have a intranet web site that displays a hyperlink if the subfolder on
the network file system contains 1 or more physical files. The file system
is pointed to by a virtual directory on our web site. I am using the code
below to check for existing folder and if not found, create it. My problem
is that sometimes the subfolder name does not exactly match the name we are
looking for. However, if the 1st 4 characters are the same I want to
consider it a match (found directory) but I don't know how to do that. I
also want to use the GetFiles with that partial match to get the file count.
Can anyone help? Thanks.

David

If My.Computer.FileSystem.DirectoryExists(strPath) = False Then

My.Computer.FileSystem.CreateDirectory(strPath)

End If

If My.Computer.FileSystem.GetFiles(strPath).Count = 0 Then

varCtl = e.Row.FindControl("HLViewDocs")

varCtl.Text = ""

Else

e.Row.Cells(11).CssClass = "Show"

End If
 
Howdy,

Dim path As String = "c:\temp\myDir"
Dim directoryExists As Boolean = System.IO.Directory.Exists(path)

If Not directoryExists Then

Dim parentDirectory As String = _
System.IO.Path.GetDirectoryName(path)
Dim searchPattern As String = _
System.IO.Path.GetFileName(path).Substring(0, 4) & "*"

directoryExists = System.IO.Directory.GetDirectories( _
parentDirectory, _
searchPattern, _
System.IO.SearchOption.TopDirectoryOnly).Length > 0

End If

If Not directoryExists Then
System.IO.Directory.CreateDirectory(path)
End If

Hope this helps
 
I'll give it a try. Thank you.
-David
Milosz Skalecki said:
Howdy,

Dim path As String = "c:\temp\myDir"
Dim directoryExists As Boolean = System.IO.Directory.Exists(path)

If Not directoryExists Then

Dim parentDirectory As String = _
System.IO.Path.GetDirectoryName(path)
Dim searchPattern As String = _
System.IO.Path.GetFileName(path).Substring(0, 4) & "*"

directoryExists = System.IO.Directory.GetDirectories( _
parentDirectory, _
searchPattern, _
System.IO.SearchOption.TopDirectoryOnly).Length > 0

End If

If Not directoryExists Then
System.IO.Directory.CreateDirectory(path)
End If

Hope this helps
 
Back
Top