Previous Topic: GetDrive - Return the Current Drive NumberNext Topic: GetFileSize - Return the Size of the File


GetFileAttributes - Return the File Attributes

Valid on NetWare, Symbian OS, UNIX, Windows and Windows CE

The GetFileAttributes function retrieves the attributes of the file or directory indicated by file name.

This function has the format:

GetFileAttributes(filename as String) as Integer
filename

Identifies the file path.

The following list indicates the value of the file attributes for all supported Windows platforms. Parameter values are decimal.

READONLY

Value: 1

HIDDEN

Value: 2

SYSTEM

Value: 4

DIRECTORY

Value: 16

ARCHIVE

Value: 32

NORMAL

Value: 128

TEMPORARY

Value: 256

COMPRESSED

Value: 2048

OFFLINE

Value: 4096

On successful completion, the function returns a value containing the attributes of the specified file or directory. If the file does not exist, the function returns the value -1.

Example: GetFileAttributes function

This example reports the attributes on AUTOEXEC.BAT and switches the Hidden flag.

dim attr as integer
dim out as string

attr=GetFileAttributes("C:BAT")
if (attr<>-1) then
	 out=out+"Attributes: "+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("Information on C:\AUTOEXEC.BAT"+chr(10)+chr(10)+out)
else
	 MsgBox("Cannot find C:\AUTOEXEC.BAT")
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: