|
-
Aug 19th, 2000, 07:28 PM
#1
Take a look at this thread. It will show how to list all subdirectories. I am almost sure you can list all files the way I showed using the code as well. I don't know about getting the Directories sizes though.
-
Aug 19th, 2000, 07:36 PM
#2
transcendental analytic
Code:
'Put this in a classmodule
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
'And this in a form
Private WithEvents sd As subdirs
Public Dirsize As Long
Private Sub sd_Filecatch(File As String, Path As String, level As Integer)
Dirsize = Dirsize + FileLen(Path & "\" & File)
End Sub
Private Sub Form_Load()
Set sd = New subdirs
Dirsize = 0
sd.explore "C:\Windows"
MsgBox Dirsize
End Sub
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.
-
Aug 28th, 2000, 07:56 AM
#3
Lively Member
Hi! Thanks for your help on this but I keep getting:
Compile Error:
User-defined type not defined
on the following line:
Private WithEvents sd As subdirs
Any ideas?
Cheers
Simon
-
Aug 29th, 2000, 04:39 AM
#4
transcendental analytic
You used my class? then you should rename it to "subdirs".
But i really recommend the API version, it's lot faster. But on the other hand if you want to have the files dropping in and speed is of no importance you could use my class
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.
-
Aug 29th, 2000, 06:03 AM
#5
Lively Member
API? Where do I get that from 
Simon
-
Aug 29th, 2000, 06:45 AM
#6
Originally posted by Batman
But, it will only work on normal subdirectories. If subdirectories have attributes of read-only, your program does not work. You need to change all lines that are like this.
Code:
If GetAttr(Temp & CurrentFolder) = vbDirectory Then
'Change to this
Code:
If GetAttr(Temp & CurrentFolder) >= vbDirectory Then
Or you could do like this:
Code:
If (GetAttr(Temp & CurrentFolder) And vbDirectory) = vbDirectory Then
-
Aug 29th, 2000, 07:48 AM
#7
_______
<?>
As kedaman said:
use the findfirst api to get first file in folder
then use findnext to get next till you have them all
in between all that as you get each file in the folder
you use FileLen(thefile) to get it's size and just keep
accumulating the totals
You can get the API FindFirst and FindNext here:
http://www.vbapi.com/ref/funca.html#f
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|