当前位置:系统之家 > 技术开发教程 > 详细页面

改变文件的属性

改变文件的属性

更新时间:2024-03-27 文章作者:未知 信息来源:网络 阅读次数:

想要读取一个文件的属性,就要用FileGetAttr函数调用文件名,即将文件属性返回到一指定文件。例如,添加一个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;
---------------------------
    要想设置某个文件的属性,将你想要改变的文件名和要改的属性传递到函数FileSetAttr。每种属性都在SysUtils单元中定义了一个名称。要设置某个文件的属性,请您跟着做下去:

Attributes := Attributes or faSystem;

//也可以同时设置几个属性:

Attributes := Attributes and not (faReadOnly or faHidden);
---------------------------
//另外,为了改变文件属性,可以使用下面的返回值。
     +----------------------------------+
     | 返回值 | 文件属性 |
     +----------------------------------+
     | 128 | Normal |
     | 1 | Read Only |
     | 2 | Hidden |
     | 4 | System |
     | 32 | Archive |
     +--------------+-------------------+

调用示例:我们将用到如下代码

FileSetAttr('C:\Autoexec.bat',2);{隐藏}
FileSetAttr('C:\Autoexec.bat',3);{隐藏、只读。FileGetAttr 返回值3} 

温馨提示:喜欢本站的话,请收藏一下本站!

本类教程下载

系统下载排行