Vb Directory program Help

vbcom004

Newcomer
Joined
Feb 18, 2008
Messages
1
Hi I am trying to create a program that will read a text file and create a directory type of structure based on the contents in the text file. Basically each line in the text file should have a directory name, a number of
subdirectories and the prefix name of the subdirectory.It should allow the worker to select from a drop down menu“Create Folder Structure”
and have the program read the text file and update
the directory structure under the same directory
as the text file with the information from the
contents in the file. If anyone could help me start this that would be great or if you can tell me where to go to hire someone to help design this that would help too.
 
Your application looked like fun...so, I built it. I created a simple text file, then created a class with 3 methods:

1. LoadStructureChoices(ByVal cbo As ComboBox) - this method reads and parses the text file. It adds the first field of each line to the combo box which is passed as an argument.

2. ShowDirectoryPreview(ByVal StructureSelected As String, ByVal lb As ListBox) - I created this method to add Preview functionality to the application, giving the user a visual clue into the structure they've selected before they select to create the structure. It reads the text file looking at only the first entry of each line. If a match is found, that entry is added to the listbox. Subsequent fields of that line are listed beneath the main directory and indented to show a hierarchy.

3. CreateDirectoryStructure(ByVal StructureSelected As String) - I didn't spend the time to allow users to select a location to create the structure, but that should be simple enough. This method, again, finds a matching line in the file and uses the line entries to create the directory and subdirectories.

That was a lot of fun. So, thanks. I need to read the rules of the forum, I'm a newbie too...I'm not sure how they feel about posting code before allowing someone to try it on their own. As a Software Development instructor...I would understand that.

Good luck to you. I'll keep watching for your progress. I'm curious, what is the intent of the sub directory prefix that you mentioned?
 
Last edited:
I've read the rules, and I believe it legal to help get you started. If you've gotten this far, forgive my posting this sample: your post didn't indicate how much of the application you've completed. Anyway, here's a sample function which should get you started...at least with loading the available selections into a combo box.

Code:
Imports System.Windows.Forms
Imports System.IO
Imports Microsoft.VisualBasic.FileIO

Public Class clsDirectoryStructures

    Public Sub LoadStructureChoices(ByVal cbo As ComboBox)

        Dim InputFile As String = Application.StartupPath & "\DirectoryStructures.txt"
        Dim CurrentLine As String()
        Dim CurrentField As String
        Dim StructureLoaded As Boolean
        Dim FileReader As TextFieldParser = My.Computer.FileSystem.OpenTextFieldParser(InputFile)

        FileReader.TextFieldType = FieldType.Delimited
        FileReader.Delimiters = New String() {";"}

        If My.Computer.FileSystem.FileExists(InputFile) Then
            While Not FileReader.EndOfData
                StructureLoaded = False
                Try
                    CurrentLine = FileReader.ReadFields
                    For Each CurrentField In CurrentLine
                        If StructureLoaded = False Then
                            cbo.Items.Add(CurrentField.ToString())
                            StructureLoaded = True
                        End If
                    Next
                Catch ex As Exception
                    MessageBox.Show("An error occurred while loading available structures." _
                    & Environment.NewLine _
                    & "Description: " & ex.ToString(), "File Structures", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                End Try
            End While
        Else
            MessageBox.Show("An error has occurred." _
            & Environment.NewLine _
            & "Description: Unable to locate DirectoryStructures.txt", "File Structures", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End If

        If cbo.Items.Count > 0 Then cbo.SelectedIndex = 0
    End Sub

End Class
 
Last edited:
Back
Top