FileGetSize

首页  后退  前进

FileGetSize
down2

FileGetSize

返回文件的字节大小.

 

FileGetSize ( "filename" )

参数

filename

目标文件名.

返回值

成功:

返回文件的字节大小.

失败:

返回 0, 设置 @error 为非 0

备注

本函数对目录无效.

返回的结果除以 1024 即为 KB(千字节), 或除以 1048576 即为 MB(兆字节).

 

函数示例

#include <MsgBoxConstants.au3>
Example()
Func Example()
    ; Retrieve the file size (in bytes) of the AutoIt executable.
    Local $iFileSize = FileGetSize(@AutoItExe)
    ; Display the file size and convert to a readable form.
    MsgBox($MB_SYSTEMMODAL, "", ByteSuffix($iFileSize))
EndFunc   ;==>Example
Func ByteSuffix($iBytes)
    Local $iIndex = 0, $aArray = [' bytes', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB']
    While $iBytes > 1023
        $iIndex += 1
        $iBytes /= 1024
    WEnd
    Return Round($iBytes) & $aArray[$iIndex]
EndFunc   ;==>ByteSuffix

----------------------------------------

 

该函数可以通过命令 exect 调用

参见:

DirGetSize, FileGetAttrib, FileGetTime, DriveSpaceTotal, FileGetVersion

例子
copy

exect=$var_i=FileGetSize('C:\Test\test.txt')||_ViewValues('$var_i') ;; 以字节返回test.txt文件的大小

 

exect=$var_i=Round(FileGetSize('C:\Test\test.txt')/1024)||_ViewValues('$var_i') ;; 以千字节的形式返回文件test.txt的大小

 

exect=$var_i=Round(FileGetSize('C:\Test\test.txt')/1024/1024)||_ViewValues('$var_i') ;; 以兆字节返回文件test.txt的大小

up2

tcimage © Аверин Андрей для Total Commander Image Averin-And@yandex.ru