Results 1 to 5 of 5

Thread: directory loop

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Posts
    168
    Hello, I am trying to write a program that loops every every file/sub-dir in a specified path and repair/compact every MDB it finds. I have figured out how to repair/compact the db, but how do I loop through every file in a specified path? Like I would tell the program to start at S:\DATA and it would find all of the MDB's in S:\DATA and its sub-dirs and repair/compact the db. Any help would be appreciated, thanks!

    Thai

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    might help..

    'loop through a dir

    Dim sDir As String
    sDir = Dir("C:\*.*", vbNormal + vbHidden + vbArchive + vbReadOnly + vbSystem)
    While sDir <> ""
    sDir = Dir
    'do whatever

    Wend
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Posts
    168
    That doesn't check the subdirectories and it also doesn't return the full path of the filename. I need something that will loop through every sub dir also and return the full path so I can plug it into my repair/compact function.

    Thanks though,
    Thai

  4. #4
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325
    A recursive function is what you need.

    Function rec_dir_func
    root dir
    repair files if any found
    Loop Through list of sub dirs in root dir
    rec_dir_func(new root path)
    Next Loop
    End Function
    -Shickadance

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    For subdirectories and files:
    This is my classmodule from which you can fire the events, but you can simply put your own code instead of the raisevent statements.
    Code:
    Option Explicit
    Event Filecatch(File As String, Path As String, level As Integer)
    Event Direcatch(dire As String, Path As String, level As Integer)
    Public curlevel%
    Public filemax&
    Public diremax&
    Public tid&
    Sub explore(startdir$, Optional pauses = 100)
    Dim tids&
        tids = Timer
        filemax = 0: diremax = 0:  curlevel = 0
        If Right(startdir, 1) <> "\" Then startdir = startdir & "\"
        SubFiles startdir, pauses
    
        tid = Timer - tids
    End Sub
    
    Function SubFiles(Path$, Optional pauses = 100): Dim i&, dmax&, dirname$, dire$(), waiter&
        dirname = Dir(Path, 63)
        Do While dirname <> ""
            If dirname <> "." And dirname <> ".." Then
                If Int(GetAttr(Path + dirname) / 16) Mod 2 = 1 Then
                        If (dmax Mod 10) = 0 Then
                            ReDim Preserve dire(dmax + 10)    ' Resize the array.
                        End If
                    diremax = diremax + 1: dmax = dmax + 1
                    dire(dmax) = dirname
                    RaiseEvent Direcatch(dirname, Path, curlevel)
                Else
                    filemax = filemax + 1
                    RaiseEvent Filecatch(dirname, Path, curlevel)
                End If
            End If
                dirname = Dir   ' Get another directory name.
            waiter = waiter + 1: If waiter Mod (pauses) = 1 Then DoEvents
        Loop
        For i = 1 To dmax
            curlevel = curlevel + 1
            SubFiles Path & dire(i) & "\"
        Next i
        curlevel = curlevel - 1
    End Function
    [Edited by kedaman on 06-19-2000 at 08:29 PM]
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width