Hello Group!

I've written an app that saves the updated info into a network file folder based on the property number (I'm in the hotel industry). Currently I have a text file with the individual folder names that I've hand written so the app knows where to store the data. However that's proven to be inefficient as properties are being added requently and, for some unknown reason, the folder names seem to change (probably because of someone's personal reason). I need to "fix" this. My thoughts are to:

1) write some code that will read the name of each folder in that network file path and store those names on my (now handwritten) text file
2) re-write the code in the app to use a wildcard to find where to store the data on its own. To clarify: all of our property folders begin with it's property number (i.e. "208" or "1203", etc.).

With either of these, I'm not sure if that can be done much less how to do it. If it's possible, I'd prefer to consider option 2.

If it helps, the property folders read as "1504 - FPbs Meriden" or "3363 - Aloft Charlotte Ballantyne". Is there a way that I use code to instruct the app to save the data in the folder just using "1504"?

In advance, thanks for your help.

Don

Recommended Answers

All 5 Replies

Well Don, if you want the group to improve on your app you have to show us the code.

You could iterate through the folder names and look for one starting with "1504 -".

Hi Don,
Are the digits unique for each folder name?
If there is an only one folder that you mension 1504 - FPbs Meriden, no other folder is there which uses 1504 like 1504 - XXXXXXXX, you can do it for that particular folder. If you have another one which contains the digits 1504, you must have choose the appropriate folder name.
You can use StringVariable.Contains(Value) method to detect the appropriate ones.
Hope it can give you a way to solve your problem.

When you say "handwritten", do you mean "hard coded"?

If it contains a " - " after the number, read all directory names using one of the methods in System.IO.DirectoryInfo. To extract the property number, use stringVariableName.Substring(0, stringVariableName.IndexOf ("-") - 2).

Public Function getFolderNameGDI(ByVal fullyQualifiedFolderName As String, ByVal propertyNumber As String)

    'property number followed by a space and a "-"
    Dim searchPattern = propertyNumber & " - " & "*"

    'Debug.WriteLine("searchPattern: '" & searchPattern & "'")

    Dim di As New System.IO.DirectoryInfo(fullyQualifiedFolderName)
    Dim dirInfoArr() As System.IO.DirectoryInfo = di.GetDirectories(searchPattern, System.IO.SearchOption.TopDirectoryOnly)

    'return directory that matches searchPattern
    For Each d As System.IO.DirectoryInfo In dirInfoArr
        'Debug.WriteLine("dirName GD: " & fqDirName)
        Return d.FullName
    Next

    Return String.Empty
End Function
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.