delphi获取文件或文件夹属性和修改属性


本文整理自网络,侵删。

  

语句片段:

function showAttr(path:string) : integer;

var

Attributes:word;

begin

Attributes := fileGetAttr(PANsiChar(path));

if (Attributes and faHidden) = faHidden then //faHidden 便是"隐藏"属性

begin

语句块

end;

if (Attributes and faReadOnly) = faReadOnly then //faReadOnly 只读属性

begin

语句块

end;

if (Attributes and faSysFile) = faSysFile then //faSysFile 系统属性

begin

语句块

end;

if (Attributes and faArchive) = faArchive then //faSysFile 系统属性

begin

语句块

end;

end;

修改属性

代码片段

var //隐藏d:\132.txt

attr:integer;

begin

attr := fileGetAttr('D:\123.txt');
if not ( (attr and faHidden) = faHidden )then
begin
fileSetAttr('D:\123.txt',attr or faHidden);
MessageBox(0,' 完成','提示',MB_OK);
end;

end;

var //显示d:\123.txt
attr : integer;
begin
attr := FileGetAttr('D:\123.txt');
if ( (attr and faHidden) = faHidden ) then
begin
setFileAttributes('D:\123.txt',(attr and (not faHidden)));
MessageBox(0,' 完成','提示',MB_OK);
end;
end;

附文件属性常量

faReadOnly $00000001 Read-only files 只读文件

faHidden $00000002 Hidden files 隐藏文件

faSysFile $00000004 System files 系统文件

faVolumeID $00000008 Volume ID files 卷标文件

faDirectory $00000010 Directory files 目录

faArchive $00000020 Archive files 归档文件

faAnyFile $0000003F Any file 任意文件

相关阅读 >>

Delphi生成的webservice appdebug的程序,编译时出错

Delphi循环移位操作

Delphi d10.x 并行库ppl编程之ttask

Delphi 的内存操作函数(1): 给字符指针分配内存

Delphi 获得父目录�c指定级父目录

Delphi sqlite 自动编号的实现

Delphi 关闭uac 单元

Delphi 10.2 新特性之―tfdbatchmovejsonwriter

Delphi 虚拟桌面原理及实现

Delphi 命令行 打开读写txt文件

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...