일부 파일/폴더 사용 데이터를 수집하려면이 응용 프로그램에서 일하고 있습니다. 목표는 객체에 파일 및 하위 폴더의 크기를 알리는 것입니다. 나무의 모든 지점에서.(Reverse?) 트리 열거 형
내 문제는; 내 객체에 디렉토리 구조를 가져온 후에는 거기에 부분합을 가져 오는 방법에 당황 스럽습니다.
실제로 나무를 만들 때 합계를 추가 할 수 있습니까? 아니면 내가 역순으로 나무를 밟아야합니까 (특히 혼란스럽게 보입니다 ...)
저는 컴퓨터 과학 교육이없는 초보자입니다. Google에 적절한 용어를 알고 있다면 그 답은 분명히있을 것입니다.
내 수업은 당신이 하위 노드를 호출하는 각 노드에있는 모든 파일 크기를 추가 한 후
Imports System.IO
Public Class Form1
Public Class mrFURDirectory
Public Property Name As String
Public Property FileSize As Long = 0
Public Property FileCount As Long = 0
Public Property DirSize As Long = 0
Public Property DirCount As Long = 0
Public Property Parent As mrFURDirectory
Public Property Children As New List(Of mrFURDirectory)
Public Property PercentOfParent As Short = 0
Public Property DirChecked As Boolean = False
Public Sub New(ByVal Name As String)
Me.Name = Name
End Sub
End Class
Public Class mrBaseFURDirectory
Inherits mrFURDirectory
Property RootPath As String
Sub New(ByVal Name As String, ByVal RootPath As String)
MyBase.New(Name = Name)
Me.RootPath = RootPath
End Sub
End Class
Dim BaseDirectory As New mrBaseFURDirectory("A:\", "a:\") 'RAM disk full files/folders
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'setup IO
Dim IOBaseDirectory As IO.DirectoryInfo
IOBaseDirectory = New IO.DirectoryInfo(BaseDirectory.RootPath)
'go get 'em tiger!
GatherChildDirectoryStats(IOBaseDirectory, BaseDirectory)
MsgBox("Done.")
End Sub
Public Sub GatherChildDirectoryStats(ByVal IODirectory As IO.DirectoryInfo, ByVal FURDirectory As mrFURDirectory)
'get the file count and total size of files in this directory
For Each aFile As IO.FileInfo In IODirectory.GetFiles
FURDirectory.FileSize += aFile.Length
FURDirectory.FileCount += 1
Next
For Each Directory As IO.DirectoryInfo In IODirectory.GetDirectories
'DirCount likely redundant..
FURDirectory.DirCount += 1
'if we're in here, we need another child, make one
Dim NewChildDir As mrFURDirectory
'attach it to the parent
FURDirectory.Children.Add(New mrFURDirectory(Directory.Name))
'reference the child
NewChildDir = FURDirectory.Children(FURDirectory.Children.Count - 1)
'tell the child who the parent is
NewChildDir.Parent = FURDirectory
'recurse into sub again
GatherChildDirectoryStats(Directory, NewChildDir)
Next
End Sub
'FURDirectory.DirSize + = NewChildDir.FileSize + NewChildDir.DirSize' (즉, 현재 값을 바꾸지 않고 현재 새 자식을 현재 값에 추가)입니다. – Chris
@Chris 예, 물론 발견해 주셔서 감사합니다. –
고마워, 그 트릭을. – PuzzledAboutVB