Function Reference


FileSetAttrib

Sets the attributes of one or more files/directories.

FileSetAttrib ( "file pattern", "+-RASHNOT" [, recurse = 0] )

Parameters

file pattern The path of the file(s) to set, e.g. C:\*.au3, C:\Dir. (* and ? wildcards accepted - See Remarks)
+-RASHNOT Attribute(s) to set/clear. e.g. "+A", "+RA-SH"
recurse [optional]
    $FT_NONRECURSIVE (0) - no recursion (Default)
    $FT_RECURSIVE (1) - directories are recursed into.

Constants are defined in FileConstants.au3.

Return Value

Success: 1.
Failure: 0 if encountered any errors.

Remarks

See FileFindFirstFile() for a discussion about wildcards.

The file pattern cannot contain spaces!
The attributes that can be modified with the function are + or -:
    "R" = READONLY
    "A" = ARCHIVE
    "S" = SYSTEM
    "H" = HIDDEN
    "N" = NORMAL
    "O" = OFFLINE
    "T" = TEMPORARY

(Note that you cannot set the compressed/directory attributes with this function.)

Related

FileGetAttrib, FileGetTime, FileSetTime

Example

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>

If MsgBox(($MB_YESNO + $MB_SYSTEMMODAL), "", "Note: This is an example and shouldn't be run under normal circumstances. " & @CRLF & @CRLF & "Do you wish to run the example?") = $IDYES Then
        ; Mark all .au3 files in current directory as read-only and system.
        If Not FileSetAttrib(@ScriptDir & "\*.au3", "+RS") Then
                MsgBox($MB_SYSTEMMODAL, "Error", "Problem setting attributes.")
        EndIf

        ; Mark all .bmp files in @HomeDrive and sub-directories writable and archived.
        If Not FileSetAttrib(@HomeDrive & "\*.bmp", "-R+A", $FT_RECURSIVE) Then
                MsgBox($MB_SYSTEMMODAL, "Error", "Problem setting attributes.")
        EndIf
EndIf