Rubrique précédente: RenameFile : Renommer ou déplacer un fichierRubrique suivante: SetFileTime : Définir des horodateurs pour un fichier ou un répertoire


SetFileAttributes – Définir les attributs des fichiers

Valide sur les plates-formes NetWare, Symbian OS, UNIX, Windows et Windows CE

La fonction SetFileAttributes définit les attributs du fichier ou du répertoire spécifié par le nom de fichier.

Cette fonction de contenu de fichier présente le format suivant :

SetFileAttributes(filename as String,attr as Integer) as Boolean
filename

Indique le chemin du fichier.

attr

Indique la valeur à définir.

Windows

La liste suivante indique les valeurs des attributs de fichiers sous Windows. Les valeurs des paramètres sont décimales.

READONLY

Valeur : 1

MASQUE

Valeur : 2

SYSTEM

Valeur : 4

DIRECTORY

Valeur : 16

ARCHIVE

Valeur : 32

NORMAL

Valeur : 128

TEMPORARY

Valeur : 256

COMPRESSED

Valeur : 2048

HORS LIGNE

Valeur : 4096

Pour la liste des attributs de fichier pris en charge sous UNIX, reportez-vous à la section Attributs de fichier UNIX.

Exemple : Fonction SetFileAttributes

Cet exemple répertorie les attributs de AUTOEXEC.BAT et modifie l'indicateur Hidden.

dim attr as integer
dim out as string

attr=GetFileAttributes("C:BAT")
if (attr<>-1) then
	 out=out+"Attributs : "+chr(9)+"["
	 if attr and FA_ARCHIVE then out=out+"A"
	 if attr and FA_SYSTEM then out=out+"S"
	 if attr and FA_HIDDEN then out=out+"H"
	 if attr and FA_RDONLY then out=out+"R"

	 out=out+"]"
	 MsgBox("Informations sur C:\AUTOEXEC.BAT"+chr(10)+chr(10)+out)
else
	 MsgBox("C:\AUTOEXEC.BAT est introuvable")
end if
if attr and FA_HIDDEN then
	attr = attr - FA_HIDDEN
	SetFileAttributes("C:\AUTOEXEC.BAT", attr)
else
	attr = attr + FA_HIDDEN
	SetFileAttributes("C:\AUTOEXEC.BAT", attr)
End If
end: