Click to See Complete Forum and Search --> : Batch process directories
madddog
Jan 9th, 2000, 02:51 AM
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
Al Smith
Jan 9th, 2000, 05:26 AM
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)
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:asmith3914@aol.com[/email]
<A HREF="mailto:asmith@spxateg.com">asmith3914@aol.com">asmith@spxateg.com">asmith3914@aol.com</A>
[email]asmith@spxateg.com</A>
[This message has been edited by Al Smith (edited 01-09-2000).]
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.