想要讀取一個文件的屬性,就要用FileGetAttr函數(shù)調(diào)用文件名,即將文件屬性返回到一指定文件。例如,添加一個Tbutton和Tlabel組件到窗體并添加如下代碼:
var attr:Integer; s:string; begin attr:=FileGetAttr('c:\Autoexec.bat'); if(attr and faHidden)<>0 then s:='Hidden'; if(attr and faReadOnly)<>0 then s:=s+'Read-Only'; if(attr and faSysFile)<>0 then s:=s+'System'; if(attr and faArchive)<>0 then s:=s+'Archive'; Label1.Caption:=s; end; --------------------------- 要想設(shè)置某個文件的屬性,將你想要改變的文件名和要改的屬性傳遞到函數(shù)FileSetAttr。每種屬性都在SysUtils單元中定義了一個名稱。要設(shè)置某個文件的屬性,請您跟著做下去:
Attributes := Attributes or faSystem;
//也可以同時設(shè)置幾個屬性:
Attributes := Attributes and not (faReadOnly or faHidden); --------------------------- //另外,為了改變文件屬性,可以使用下面的返回值。 +----------------------------------+ | 返回值 | 文件屬性 | +----------------------------------+ | 128 | Normal | | 1 | Read Only | | 2 | Hidden | | 4 | System | | 32 | Archive | +--------------+-------------------+
調(diào)用示例:我們將用到如下代碼
FileSetAttr('C:\Autoexec.bat',2);{隱藏} FileSetAttr('C:\Autoexec.bat',3);{隱藏、只讀。FileGetAttr 返回值3}
|