FileGetAttrib

首页  后退  前进

FileGetAttrib
down2

FileGetAttrib

返回文件的属性代码.

 

FileGetAttrib ( "filename" )

参数

filename

检查文件或目录的路径.

返回值

成功:

返回文件属性的代码字符串.

失败:

返回 "" (空字符串), 设置 @error 为 1.

备注

String() 返回的字符串可能包含 "RASHNDOCT" 字符的组合:

   "R" = 只读文件

   "A" = 存档文件

   "S" = 系统文件

   "H" = 隐藏文件

   "N" = 普通文件

   "D" = 目录文件

   "O" = 脱机文件

   "C" = 压缩文件 (NTFS 压缩, 并非 ZIP/RAR 压缩)

   "T" = 临时文件

   "X" = EFS 加密

 

函数示例

示例 1

#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
Example()
Func Example()
    ; Create a constant variable in Local scope to store the file attributes of the current script.
    Local Const $sAttribute = FileGetAttrib(@ScriptFullPath)
    ; Display the string returned by FileGetAttrib.
    MsgBox($MB_SYSTEMMODAL, "", "The attribute string: " & @CRLF & $sAttribute)
    ; Display the string returned by AttributeToString
    MsgBox($MB_SYSTEMMODAL, "", "The attribute string with easier to understand values: " & @CRLF & _
            AttributeToString($sAttribute))
EndFunc   ;==>Example
Func AttributeToString($sAttribute)
    ; Create a 1d array of the file attribute letters by splitting the string at the comma (,).
    Local $aInput = StringSplit("R,A,S,H,N,D,O,C,T", ",")
    ; Create a 1d array using the friendlier file attribute names by splitting the string at the comma (,).
    Local $aOutput = StringSplit("Read-only /, Archive /, System /, Hidden /" & _
            ", Normal /, Directory /, Offline /, Compressed /, Temporary /", ",")
    ; Loop through the attribute letters array to replace with the friendlier value e.g. A becomes Archive or S becomes System.
    For $i = 1 To $aInput[0]
        $sAttribute = StringReplace($sAttribute, $aInput[$i], $aOutput[$i], 0, $STR_CASESENSE)
    Next
    ; Remove the single space and trailing forward slash.
    $sAttribute = StringTrimRight($sAttribute, 2)
    ; Return the attribute string.
    Return $sAttribute
EndFunc   ;==>AttributeToString

示例 2

#include <MsgBoxConstants.au3>
Example()
Func Example()
    ; Assign a variable with the filepath to check on whether it's a file or not.
    Local $sFilePath = @ScriptFullPath
    If IsFile($sFilePath) Then
        MsgBox($MB_SYSTEMMODAL, "", "The filepath is a file.")
    Else
        MsgBox($MB_SYSTEMMODAL, "", "The filepath is not a file.")
    EndIf
EndFunc   ;==>Example
; Check if the filepath is a file. Does not validate if the file exists.
Func IsFile($sFilePath)
    Return StringInStr(FileGetAttrib($sFilePath), "D") = 0
EndFunc   ;==>IsFile

示例 3

#include <MsgBoxConstants.au3>
Example()
Func Example()
    ; Assign a variable with the filepath to check on whether it's a directory/folder or not.
    Local $sFilePath = @ScriptDir
    If IsDir($sFilePath) Then
        MsgBox($MB_SYSTEMMODAL, "", "The filepath is a directory/folder.")
    Else
        MsgBox($MB_SYSTEMMODAL, "", "The filepath is not a directory/folder.")
    EndIf
EndFunc   ;==>Example
; Check if the filepath is a directory/folder. Does not validate if the directory/folder exists.
Func IsDir($sFilePath)
    Return StringInStr(FileGetAttrib($sFilePath), "D") > 0
EndFunc   ;==>IsDir

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

 

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

参见:

FileSetAttrib, FileGetTime, FileExists, FileGetSize, FileSetTime

例子
copy

exect=$var_s=FileGetAttrib('C:\pagefile.sys')||_ViewValues('$var_s') ;; 返回一个与pagefile.sys文件的属性相匹配的字符串

 

exect=$var_i=(StringInStr(FileGetAttrib('%P%N'),'D')~~And~~FileExists('%P%N'))?1:0||_ViewValues($var_i) ;; 检查:返回1,如果在光标文件夹下,0  - 如果文件

up2

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