На главную Наши проекты:
Журнал   ·   Discuz!ML   ·   Wiki   ·   DRKB   ·   Помощь проекту
ПРАВИЛА FAQ Помощь Участники Календарь Избранное RSS
msm.ru
Модераторы: SCINER, B.V.
  
    > Как определить размер папки
      ExpandedWrap disabled
        Const MAX_PATH = 260
         
        Private Type FILETIME
        dwLowDateTime As Long
        dwHighDateTime As Long
        End Type
         
        Private Type WIN32_FIND_DATA
        dwFileAttributes As Long
        ftCreationTime As FILETIME
        ftLastAccessTime As FILETIME
        ftLastWriteTime As FILETIME
        nFileSizeHigh As Long
        nFileSizeLow As Long
        dwReserved0 As Long
        dwReserved1 As Long
        cFileName As String * MAX_PATH
        cAlternate As String * 14
        End Type
         
        Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
        Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
        Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
         
        Public Function SizeOf(ByVal DirPath As String) As Double
        Dim hFind As Long
        Dim fdata As WIN32_FIND_DATA
        Dim dblSize As Double
        Dim sName As String
        Dim x As Long
        On Error Resume Next
        x = GetAttr(DirPath)
        If Err Then SizeOf = 0: Exit Function
        If (x And vbDirectory) = vbDirectory Then
        dblSize = 0
        Err.Clear
        sName = Dir$(EndSlash(DirPath) & "*.*", vbSystem Or vbHidden Or vbDirectory)
        If Err.Number = 0 Then
        hFind = FindFirstFile(EndSlash(DirPath) & "*.*", fdata)
        If hFind = 0 Then Exit Function
        Do
        If (fdata.dwFileAttributes And vbDirectory) = vbDirectory Then
        sName = Left$(fdata.cFileName, InStr(fdata.cFileName, vbNullChar) - 1)
        If sName <> "." And sName <> ".." Then
        dblSize = dblSize + SizeOf(EndSlash(DirPath) & sName)
        End If
        Else
        dblSize = dblSize + fdata.nFileSizeHigh * 65536 + fdata.nFileSizeLow
        End If
        DoEvents
        Loop While FindNextFile(hFind, fdata) <> 0
        hFind = FindClose(hFind)
        End If
        Else
        On Error Resume Next
        dblSize = FileLen(DirPath)
        End If
        SizeOf = dblSize
        End Function
         
        Private Function EndSlash(ByVal Path As String) As String
         
        EndSlash = IIf(Right(Path, 1) <> "\", Path & "\", Path)
         
        End Function
         
        Private Sub Form_Load()
         
        MsgBox SizeOf("D:\Games") / 1000000
        End Sub
      Сообщение отредактировано: Andrey_Kun -
      0 пользователей читают эту тему (0 гостей и 0 скрытых пользователей)
      0 пользователей:


      Рейтинг@Mail.ru
      [ Script execution time: 0,0183 ]   [ 16 queries used ]   [ Generated: 27.04.24, 17:25 GMT ]