PDA

View Full Version : سوال: سایز یک فایل



.:KeihanCPU:.
پنج شنبه 30 آبان 1387, 09:33 صبح
سلام دوستان
چه راههایی وجود داره که سایز یک فایل رو بدست بیاریم؟

مهران رسا
پنج شنبه 30 آبان 1387, 09:53 صبح
استفاده از توابع داخلی VB .
استفاده از توابع API .
استفاده از دستورات Dos .

.:KeihanCPU:.
پنج شنبه 30 آبان 1387, 09:56 صبح
ببخشید.
همین الان دو راه پیدا کردم
یکی استفاده از Eof
و دیگری استفاده از filelen




استفاده از توابع داخلی VB .
استفاده از توابع API .
استفاده از دستورات Dos .

میشه کمی از این راهها توضیح بدین

sedeh1385
پنج شنبه 30 آبان 1387, 10:28 صبح
با استفاده از تابع FileLen
دارای یک ارگومان است که مسیر را گرفته و سایز را بر به صورت بایت بر می گرداند

debugger
پنج شنبه 30 آبان 1387, 10:37 صبح
برای چک کردن سایز فایل text


if the size of (c:\xx.txt)=0 bytes then
msgbox "file is empty"

یا


Private Sub cmdShowFileSize_Click()
Dim strOldFile As String
Dim strOldSize As String
Dim strMyDir As String
Dim strMyFile As String
strMyDir = "c:\windows\desktop"
strMyFile = "readme.txt"
strOldFile = strMyDir & "\" & strMyFile
strOldSize = FileLen(strOldFile)

lblFileSize.Caption = "The file " & strOldFile & " is " & _
Format(strOldSize, "#,##0") & " bytes in size."
End Sub

با استفاده از توابع خود vb


If FileLen(App.Path & "\app.exename") > (?byte) Then Unload Me

یه نمونه دیگه


Dim fln,result
Dim fname as String

fname="c:\windows\regedit.exe"

fln = FileLen(trim(fname))
result = CInt((fln / 1024) / 1024) & " MB" & "(" & fln & " BYTES)"

Msgbox "FileSize is -->" & result

با استفاده از API


Private Const OF_READ = &H0&
Private Declare Function lOpen Lib "kernel32" Alias "_lopen" (ByVal
lpPathName As String, ByVal iReadWrite As Long) As Long
Private Declare Function lclose Lib "kernel32" Alias "_lclose" (ByVal
hFile As Long) As Long
Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long,
lpFileSizeHigh As Long) As Long
Dim lpFSHigh As Long
Public Sub GetInfoF(FilePath As String)
Dim Pointer As Long, sizeofthefile As Long
Pointer = lOpen(FilePath, OF_READ)
sizeofthefile = GetFileSize(Pointer, lpFSHigh)
Label1.Caption = sizeofthefile & " bytes"
lclose Pointer
End Sub
Private Sub command1_Click()
CommonDialog1.ShowOpen
GetInfoF CommonDialog1.filename
End Sub
Private Sub Form_Load()
With CommonDialog1
.DialogTitle = "Select a file"
.Filter = "All the files|*.*"
End With
Command1.Caption = "Select a file"
End Sub