函数参考


FileGetAttrib

返回指定文件的属性代码.

FileGetAttrib ( "文件名" )

参数

文件名 目标文件(目录)名.

返回值

成功: 返回相应的属性字符串代码.
失败: 返回一个空字符串并把 @error 设为 1.

注意/说明

本函数返回的字符串将是以下字符的组合("RASHNDOCT"):
"R" = READONLY(只读)
"A" = ARCHIVE(存档)
"S" = SYSTEM(系统文件)
"H" = HIDDEN(隐藏)
"N" = NORMAL(普通)
"D" = DIRECTORY(目录)
"O" = OFFLINE(脱机文件)
"C" = COMPRESSED (压缩,这里指 NTFS 压缩,并非指 ZIP/RAR 压缩)
"T" = TEMPORARY(临时文件)

相关

FileGetTime, FileSetAttrib, FileExists, FileGetSize, FileSetTime

示例/演示


Local $sAttribute = FileGetAttrib(@ScriptFullPath) ; Retrieve the file attributes of the running script.
If @error Then
    MsgBox(4096,"错误", "无法获得属性.")
    Exit
Else
    If StringInStr($sAttribute, "R") Then ; If the attribute string contains the letter 'R' then the file is read-only.
    MsgBox(4096,"文件属性", "只读文件.")
    EndIf
EndIf

; Create a 1D array of the file attribute letters.
Local $aInput = StringSplit("R,A,S,H,N,D,O,C,T", ",")

; Create a 1D array using the friendlier file attribute names.
Local $aOutput = StringSplit("只读 /, 存档 /, 系统 /, 隐藏 /" & _
        ", 普通 /, 目录 /, 脱机文件 /, 压缩 /, 临时 /",  ",")

; Loop through the attribute letters array to replace with the friendlier value e.g. A is replaced with Archive.
For $i = 1 To $aInput[0]
    $sAttribute = StringReplace($sAttribute, $aInput[$i], $aOutput[$i], 0, 1)
Next

; Remove the single space and trailing forward slash.
$sAttribute = StringTrimRight($sAttribute, 2)

; Display the converted attribute letters.
MsgBox(4096, "Full file attributes:", $sAttribute)