DirectoryExists on 1st 4 chars

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
 
G

Guest

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
 
D

David C

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
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top