⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dirscanner.vb

📁 Mastering VBNet Include Source Code
💻 VB
字号:
Option Strict On
Imports System.IO
Imports System.IO.Directory

Public Class DirScanner
    Public Event ScanProgress(ByVal foldersScanned As Integer)
    Private totalSize As Long
    Private nFolders As Integer

    Public Function ScanFolder(ByVal folder As String) As Long
        Dim file, dir As String
        Dim FI As FileInfo
        For Each file In Directory.GetFiles(folder)
            FI = New FileInfo(file)
            totalSize = totalSize + FI.Length
        Next
        For Each dir In Directory.GetDirectories(folder)
            nFolders = nFolders + 1
            RaiseEvent ScanProgress(nFolders)
            ScanFolder(dir)
        Next
        Return totalSize
    End Function

    Public Event ScanTimerProgress(ByVal foldersScanned As Integer, _
           ByRef cancel As Boolean)
    Dim start As Double

    Public Function ScanTimerFolder(ByVal folder As String) As Long
        Dim file, dir As String
        Dim FI As FileInfo
        Dim interval As Double
        interval = 3000
        If start = 0 Then start = Now.TimeOfDay.TotalMilliseconds
        Dim cancel As Boolean
        For Each file In Directory.GetFiles(folder)
            FI = New FileInfo(file)
            totalSize = totalSize + FI.Length
        Next
        For Each dir In Directory.GetDirectories(folder)
            If Now.TimeOfDay.TotalMilliseconds > (start + interval) Then
                RaiseEvent ScanTimerProgress(nFolders, cancel)
                If cancel Then Exit Function
                start = Now.TimeOfDay.TotalMilliseconds
            End If
            nFolders = nFolders + 1
            ScanTimerFolder(dir)
        Next
        Return totalSize
    End Function

End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -