PHP: Get Folder Size & File Count

Here is a little PHP code you can use to get the size and file count of an entire directory including sub-directories

$filename){
  if($filename!=".." && $filename!="."){
   if(is_dir($dir."/".$filename)){
    $new_foldersize = foldersize($dir."/".$filename);
    $count_size = $count_size + $new_foldersize[0];
    $count = $count + $new_foldersize[1];
   }else if(is_file($dir."/".$filename)){
    $count_size = $count_size + filesize($dir."/".$filename);
    $count++;
   }
  }
  
 }
 
 return array($count_size,$count);
}

$sample = foldersize("SAMPLE_DIRECTORY");

echo "Folder Size : " . $sample[0] . " Bytes 
" ; echo "File Count : " . $sample[1] . " Files " ; ?>

Get File MD5 Hash Using VB6

To get a file’s MD5 Hash using Visual Basic 6, download and add the following clsMD5 class to your VB project.

Download: clsMD5.zip

 

Add a command button (Command1), a text box (Text1) and use the following code:

Private Function GetFileMD5(ByVal FileName As String) As String
    Dim MD5 As New clsMD5, FF As Integer, Buff() As Byte
    Const BuffSize As Long = 2 ^ 16 ' (64 KBytes)

'    On Error GoTo ErrExit
    FF = FreeFile
    Open FileName For Binary Access Read As FF
        MD5.MD5Init

        Do Until Loc(FF) >= LOF(FF)
            If Loc(FF) + BuffSize > LOF(FF) Then
                ReDim Buff(LOF(FF) - Loc(FF) - 1)
            Else
                ReDim Buff(BuffSize - 1)
            End If

            Get FF, , Buff
            MD5.MD5Update UBound(Buff) + 1, Buff
        Loop

        MD5.MD5Final
        GetFileMD5 = MD5.GetValues
    Close FF

    Exit Function
ErrExit:
    Err.Clear
    GetFileMD5 = ""
End Function

Private Sub Command1_Click()
Text1.Text = GetFileMD5("c:\example.exe")
End Sub