Results 1 to 2 of 2

Thread: Batch process directories

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    Nashville, TN
    Posts
    114

    Post

    I am writing a program that needs to be able to process files in all the subdirectories in a drive.

    ex. x:\job 'the main directory
    \job1 'sub directory containing files
    \job2 'same type of setup (files)

    I want to be able to process the files (open print the file,then close them and go to the next) all in one big pass. currently I can do them in only one directory at a time, then load the next dir. and start over.

    Is it possible? And how do I go about it?

    Thanks in advance....
    Mike

  2. #2
    Hyperactive Member Al Smith's Avatar
    Join Date
    May 1999
    Location
    Marcellus, MI. USA
    Posts
    330

    Post

    Hi,
    This is kind of ugly but it works. It uses the "dir" command to identify the subdirectories, saves the subdir name, then runs the files within each subdir.
    (I hope I used the UBB code correctly)

    Code:
    Dim JobRootDir As String
    Dim JobSubDir As String
    Dim JobFile As String
    Dim SubDirectory() As String
    Dim Count As Integer
    Dim Job As Integer
    
    Sub RunJobs()
    JobRootDir = "x:\job\"
    JobSubDir = Dir(JobRootDir, vbDirectory)   ' Retrieve the first entry.
    Do While JobSubDir <> ""   ' Start the loop.
        If JobSubDir <> "." And JobSubDir <> ".." Then ' Ignore the root directories.
            If (GetAttr(JobRootDir & JobSubDir) And vbDirectory) = vbDirectory Then ' Use bitwise comparison to make sure JobFile is a directory.
                Count = Count + 1
                ReDim Preserve SubDirectory(Count)
                SubDirectory(Count) = JobSubDir
            End If  ' it represents a directory.
        End If
        JobSubDir = Dir    ' Get next entry.
    Loop
    For Job = 1 To Count
    JobFile = Dir(JobRootDir & SubDirectory(Job) & "\")   ' Retrieve the first entry.
    Do While JobFile <> ""   ' Start the loop.
                ' open, print, then close the file.
                Debug.Print SubDirectory(Job) 'put here just to do something
        JobFile = Dir    ' Get next entry.
    Loop
    Next job
    
    End Sub
    Al.


    ------------------
    A computer is a tool, not a toy.
    <A HREF="mailto:[email protected][/email]
    <A HREF="mailto:[email protected]"&gt;[email protected]">[email protected]"&gt;[email protected]</A>
    [email][email protected]&lt;/A&gt;




    [This message has been edited by Al Smith (edited 01-09-2000).]

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