前のトピック: GetDrive - 現在のドライブ番号を返す次のトピック: GetFileSize - ファイル サイズを返す


GetFileAttributes - ファイル属性を返す

NetWare、Symbian OS、UNIX、Windows、および Windows CE で有効です。

GetFileAttributes 関数では、filename で示されたファイルまたはディレクトリの属性が取得されます。

この関数の形式は、以下のとおりです。

GetFileAttributes(filename as String) as Integer
filename

ファイル パスを識別します。

すべての Windows プラットフォームでサポートされるファイル属性値を以下のリストに示します。 パラメータ値は 10 進数です。

READONLY

値: 1

HIDDEN

値: 2

SYSTEM

値: 4

DIRECTORY

値: 16

ARCHIVE

値: 32

NORMAL

値: 128

TEMPORARY

値: 256

COMPRESSED

値: 2048

OFFLINE

値: 4096

正常に終了した場合、この関数では、指定したファイルまたはディレクトリの属性を含む値が返されます。 ファイルが存在しない場合、この関数では、値 -1 が返されます。

例: GetFileAttributes 関数

この例では AUTOEXEC.BAT の属性がレポートされ、[非表示]フラグの切り替えが行われます。

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: