FileSetAttrib

Changes the attributes of one or more files or folders. Wildcards are supported.

FileSetAttrib Attributes , FilePattern, Mode

Parameters

Attributes

Type: String

The attributes to change. For example, "+HA-R".

To easily turn on, turn off or toggle attributes, prefix one or more of the following attribute letters with a plus (+), minus (-) or caret (^) symbol, respectively:

If no symbol precedes the attribute letters, the file's attributes are replaced with the given attributes. See example #5. To remove all attributes, use "N" on its own.

FilePattern

Type: String

If omitted, the current file of the innermost enclosing file loop will be used. Otherwise, specify the name of a single file or folder, or a wildcard pattern such as "C:\Temp\*.tmp". FilePattern is assumed to be in A_WorkingDir if an absolute path isn't specified.

Both asterisks (*) and question marks (?) are supported as wildcards. * matches zero or more characters and ? matches any single character. Usage examples:

Mode

Type: String

If blank or omitted, only files are operated upon and subdirectories are not recursed into. Otherwise, specify one or more of the following letters:

Error Handling

An Error is thrown if any files failed to be changed, with its Extra property set to the number of failures.

If files were found, A_LastError is set to 0 (zero) or the result of the operating system's GetLastError() function immediately after the last failure. Otherwise A_LastError contains an error code that might indicate why no files were found.

Remarks

The compression state of files cannot be changed with this function.

FileGetAttrib, FileGetTime, FileSetTime, FileGetSize, FileGetVersion, file loop

Examples

Turns on the "read-only" and "hidden" attributes of all files and directories (subdirectories are not recursed into).

FileSetAttrib "+RH", "C:\MyFiles\*.*", "DF"  ; +RH is identical to +R+H

Toggles the "hidden" attribute of a single directory.

FileSetAttrib "^H", "C:\MyFiles"

Turns off the "read-only" attribute and turns on the "archive" attribute of a single file.

FileSetAttrib "-R+A", "C:\New Text File.txt"

Recurses through all .ini files on the C drive and turns on their "archive" attribute.

FileSetAttrib "+A", "C:\*.ini", "R"

Copies the attributes of file2 to file1, i.e. it adds any attributes that file2 has and removes any attributes that file2 does not have.

FileSetAttrib(FileGetAttrib(file2), file1)