Directory Verification

Hi All,

I have developed a piece of software that creates directories for our firm. This creates a standard set of them so as not to have to create all of them every time. (This is a big time saver).

What i would please like to know is, how do i verify a directory so that i do not create to very similiar.

e.g. Our directories will always begin with "M:\PROJECTS\K199 Project name"

but what can hapen is:

"M:\PROJECTS\K199_Project_name" - somebody using it and using underscores instead of spaces. this can then creat 2 very simulair names !

Now the drive & base directory will always remain the same but the project name is a incemental thing. this means that everytime 1 gets added and gets a new project name. How do i verify the first 4 letters to not be the same as ones already created.

Thanks




Answer this question

Directory Verification

  • Henrik Bach

    Thank You.

    This works great

    Nightwish



  • chart

    The code you going to need is going to be something similar to


    Function SubDirectoryExistsForProject(ByVal RootDirectory As String, ByVal Project As String) As Boolean
    Dim StrDirList() As String
    Dim bFound As Boolean = False

    StrDirList = System.IO.Directory.GetDirectories(RootDirectory)
    For Each s As String In StrDirList
    If s.Substring(0, 4) = Project Then
    bFound = True
    Exit For
    End If
    Next

    Return bFound
    End Function

    This should check the first 4 letters of each of your sub folders names and return true if there is a match. You may need to add a little bit more code to make it a bit more robust such as if the folder is less than 4 characters but this should be the general basis of your code that you would need.


  • Directory Verification