(01-12-15, 09:00 PM)adel27 كتب : شكراً لتفاعلكم
أخوي أسامه المجلد اللي أبي أقيس حجمه داخله مجلدات هل الكود يعمل مع يتناسب معي ..؟
كود :
Dim CalculatedSize As Decimal
Dim TheSize As Long = Long.Parse(My.Computer.FileSystem.GetFileInfo("C:\Music\").Length)
"Dim SizeType As String = "Bالمسـار المجلدات الموجوده داخل Musicكود :
If TheSize < 1024 Then
لما أضع المسـار بهذه الطريقه يعطيني خطأ
هل تريد قياس حجم المجلد نفسة ام الملفات التى بى المجلد ؟
اذا كنت تريد قياس حجم المجلد نفسةاستخدم هذا الكود
كود :
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
Dim CalculatedSize As Decimal
Dim SizeType As String = "B"
Dim TheSize As Long = Long.Parse(DirectorySize("E:\Music\NewFolder", True))
If TheSize < 1024 Then
CalculatedSize = TheSize
ElseIf TheSize > 1024 AndAlso TheSize < (1024 ^ 2) Then 'KB
CalculatedSize = Math.Round((TheSize / 1024), 2)
SizeType = "KB"
ElseIf TheSize > (1024 ^ 2) AndAlso TheSize < (1024 ^ 3) Then 'MB
CalculatedSize = Math.Round((TheSize / (1024 ^ 2)), 2)
SizeType = "MB"
ElseIf TheSize > (1024 ^ 3) AndAlso TheSize < (1024 ^ 4) Then 'GB
CalculatedSize = Math.Round((TheSize / (1024 ^ 3)), 2)
SizeType = "GB"
ElseIf TheSize > (1024 ^ 4) Then 'TB
CalculatedSize = Math.Round((TheSize / (1024 ^ 4)), 2)
SizeType = "TB"
End If
MessageBox.Show("File size is: " & CalculatedSize.ToString & " " & SizeType, "File size", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Overloads Function DirectorySize(ByVal sPath As String, ByVal bRecursive As Boolean) As Long
Dim lngNumberOfDirectories As Long = 0
Dim Size As Long = 0
Try
Dim fil As FileInfo
Dim diDir As New DirectoryInfo(sPath)
For Each fil In diDir.GetFiles()
Size += fil.Length
Next fil
If bRecursive = True Then
Dim diSubDir As DirectoryInfo
For Each diSubDir In diDir.GetDirectories()
Size += DirectorySize(diSubDir.FullName, True)
lngNumberOfDirectories += 1
Next
End If
Return Size
Catch fex As System.IO.FileNotFoundException
' File not found. Take no action
Catch ex As Exception
' Another error occurred
Return 0
End Try
End Function

