Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Find a Directory and a List of Files
Message
De
28/09/2000 08:37:25
GW Gross
{Banned by Information Security Policy}
Lake Mary, Floride, États-Unis
 
 
À
Tous
Information générale
Forum:
Visual Basic
Catégorie:
Codage, syntaxe et commandes
Titre:
Find a Directory and a List of Files
Divers
Thread ID:
00421964
Message ID:
00421964
Vues:
55
I have written the included code to find a subdirectory name and then create an array of all of the .mdb files in the subdirectory. Have I done a good job or is there a faster/more efficent way to do this? I used dynamic arrays to store the subdirectory names and the file names. The problem is that the subdirectory names will always be changing. The directory structure is as follows:
root
  application
      STATSDB
          0008
          0009
where the 0008 represents the statistics for a particular month. I have stored the drive:\root\application\STATSDB\ part of the path in the registry with the SaveSettings command.

I am writting my first "real" VB program and it has gotten complex fast.

Thanks for the help,

GW
Private Sub cmdGetFileNames_Click()

'Retrieve file locations paths stored in registry
Call LoadFileLocations

'Get first name
mstrWorkingString = Dir(mstrUserStatsDBDirectory, vbDirectory)

'Initialize directory count
mintDirCount = 0

'Place each name in the array mstrDirList
'Remember to exclude "." and ".." entries

Do While mstrWorkingString <> ""            'Stop when DIR function returns empty string

    If mstrWorkingString <> "." And _
       mstrWorkingString <> ".." Then       'exclude the "." and ".." directories
       
       'Redimension the array
       ReDim Preserve mstrDirList(mintDirCount)
       
       'Valid name, store in array
       mstrDirList(mintDirCount) = mstrWorkingString
       
       'Increment directory count
       mintDirCount = mintDirCount + 1
       
    End If
    
    'Get next name
    mstrWorkingString = Dir
    
Loop    'mstrWorking String <> ""

'Correct the Directory count for the last increment
mintDirCount = mintDirCount - 1

'Retrieve file names

'Read each subdirectory

'Initialize loop counter
mintLoopIndex1 = 0

'Initialize the File Counter
mintFileCount = 0

For mintLoopIndex1 = 0 To (UBound(mstrDirList))     'Process all directories in mstrDirList

    'Append subdirectory to the path,
    'don't forget to add the "\" at the end
    mstrWorkingPath = mstrUserStatsDBDirectory & _
                      Trim(mstrDirList(mintLoopIndex1)) & _
                      Chr(92)
                    
    'Get first name
    mstrWorkingString = Dir(mstrWorkingPath, vbNormal)

    'Place each MDB file name in the array mstrFileList
    'Remember to exclude "." and ".." entries

    Do While mstrWorkingString <> ""

        If mstrWorkingString <> "." And _
           mstrWorkingString <> ".." And _
           Right(Trim(mstrWorkingString), 3) = "mdb" Then
       
            'Redimension the array
            ReDim Preserve mstrFileList(mintFileCount)
       
       
            'Valid name, store in array
            mstrFileList(mintFileCount) = mstrWorkingPath & _
                                      mstrWorkingString
            'Increment the file count
            mintFileCount = mintFileCount + 1
    
        End If
    
        'Get next name
        mstrWorkingString = Dir
    
    Loop    'mstrWorkingString <> ""

Next    'mintLoopIndex1 to UBound(mstrFileList)

'Correct the file count for last increment
mintFileCount = mintFileCount - 1

'Display the results in the listbox

'Initialize the loop counter
mintLoopIndex1 = 0

'Make sure the file list is empty
lisUserStatsDatabases.Clear

For mintLoopIndex1 = 0 To UBound(mstrFileList)

    lisUserStatsDatabases.AddItem mstrFileList(mintLoopIndex1)
    
Next    'minitLoopIndex1

'Show the listbox frame
fraFileList.Visible = True

End Sub
GW Gross

"You are blessed when you're content with just who you are - no more, no less." Matthew 5:5 (The Message)
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform