delphi FileSetAttr 设置文件的属性-转
2010-05-24 09:42
393 查看
声明:function FileSetAttr ( const FileName : string; Attributes : Integer ) : Integer;
描述:FileSetAttr函数设置指定文件FileName的属性。
Attributes整数必须设为下列独立位的0个,多个或所有设置的联合。
faReadOnly:1:只读文件
faHidden:2:隐藏文件
faSysFile:4:系统文件
faVolumeID:8:卷标文件
faDirectory:16:目录文件
faArchive:32:存档文件
faSymLink:64:符号连接
如果设置功,则返回值为0,否则它包含一个错误代码。
备注:这个函数是依赖于操作系统的,比如在Linux下,Archive意味着什么也没有。
重要信息:在测试期间,作者通常会收到一个非零的返回代码,即使适当的位已经被成功设置。
{创建一个文本文件,设置为只读与系统,显示文件属性}
var
fileName : string;
myFile : TextFile;
attrs : Integer;
begin
// 尝试以写模式打开ATesstFile.tex
fileName := 'ATestFile.txt';
AssignFile(myFile, fileName);
ReWrite(myFile);
// 写入文件
Write(myFile, 'Hello World');
// 关闭文件
CloseFile(myFile);
// 设置文件为只读文件与系统文件
if FileSetAttr(fileName, faReadOnly or faSysFile) > 0
then ShowMessage('File made into a read only system file')
else ShowMessage('File attribute change failed');
// 取得文件属性
attrs := FileGetAttr(fileName);
// 显示文件属性
if attrs and faReadOnly > 0
then ShowMessage('File is read only')
else ShowMessage('File is not read only');
if attrs and faHidden > 0
then ShowMessage('File is hidden')
else ShowMessage('File is not hidden');
if attrs and faSysFile > 0
then ShowMessage('File is a system file')
else ShowMessage('File is not a system file');
if attrs and faVolumeID > 0
then ShowMessage('File is a volume ID')
else ShowMessage('File is not a volume ID');
if attrs and faDirectory > 0
then ShowMessage('File is a directory')
else ShowMessage('File is not a directory');
if attrs and faArchive > 0
then ShowMessage('File is archived')
else ShowMessage('File is not archived');
if attrs and faSymLink > 0
then ShowMessage('File is a symbolic link')
else ShowMessage('File is not a symbolic link');
end;
程序运行结果:
File made into a read only system file
File is read only
File is not hidden
File is a system file
File is not a Volume ID
File is not a directory
File is not archived
File is not a symbolic link
描述:FileSetAttr函数设置指定文件FileName的属性。
Attributes整数必须设为下列独立位的0个,多个或所有设置的联合。
faReadOnly:1:只读文件
faHidden:2:隐藏文件
faSysFile:4:系统文件
faVolumeID:8:卷标文件
faDirectory:16:目录文件
faArchive:32:存档文件
faSymLink:64:符号连接
如果设置功,则返回值为0,否则它包含一个错误代码。
备注:这个函数是依赖于操作系统的,比如在Linux下,Archive意味着什么也没有。
重要信息:在测试期间,作者通常会收到一个非零的返回代码,即使适当的位已经被成功设置。
{创建一个文本文件,设置为只读与系统,显示文件属性}
var
fileName : string;
myFile : TextFile;
attrs : Integer;
begin
// 尝试以写模式打开ATesstFile.tex
fileName := 'ATestFile.txt';
AssignFile(myFile, fileName);
ReWrite(myFile);
// 写入文件
Write(myFile, 'Hello World');
// 关闭文件
CloseFile(myFile);
// 设置文件为只读文件与系统文件
if FileSetAttr(fileName, faReadOnly or faSysFile) > 0
then ShowMessage('File made into a read only system file')
else ShowMessage('File attribute change failed');
// 取得文件属性
attrs := FileGetAttr(fileName);
// 显示文件属性
if attrs and faReadOnly > 0
then ShowMessage('File is read only')
else ShowMessage('File is not read only');
if attrs and faHidden > 0
then ShowMessage('File is hidden')
else ShowMessage('File is not hidden');
if attrs and faSysFile > 0
then ShowMessage('File is a system file')
else ShowMessage('File is not a system file');
if attrs and faVolumeID > 0
then ShowMessage('File is a volume ID')
else ShowMessage('File is not a volume ID');
if attrs and faDirectory > 0
then ShowMessage('File is a directory')
else ShowMessage('File is not a directory');
if attrs and faArchive > 0
then ShowMessage('File is archived')
else ShowMessage('File is not archived');
if attrs and faSymLink > 0
then ShowMessage('File is a symbolic link')
else ShowMessage('File is not a symbolic link');
end;
程序运行结果:
File made into a read only system file
File is read only
File is not hidden
File is a system file
File is not a Volume ID
File is not a directory
File is not archived
File is not a symbolic link
相关文章推荐
- 文件磁盘相关函数[13]-设置文件属性FileSetAttr
- Delphi 设置文件属性
- Delphi中取得和设置硬盘上文件的创建日期、修改日期、访问日期、文件属性
- 用DELPHI设置文件的属性
- 怎么修改与设置.java文件属性?
- Delphi 中 listview 根据文件扩展名 设置系统图标
- Visual Studio 中项目文件属性的Build action 设置
- Spring 中 AbstractExcelView 支持根据模板生成Excel文件. 通过设置 view 的 URL 属性指定模板的路径
- 设置文件属性
- linux文件无法删除-rw-r--r-- (用lsattr chattr设置特殊属性)
- 页面做文件上传需要设置的属性
- Delphi SetFileAttributes 功能:修改文件属性
- delphi "设置数据表属性是,再字段编辑器(Fields Editor) 的Table Properties 下拉列表中",字段编辑器在哪里呀???
- Delphi 调试器断点属性的设置
- spring 配置文件属性设置默认值以及读取环境变量值
- PDO::ATTR_EMULATE_PREPARES属性设置为false引发的血案
- 一个javabean文件,含三个属性,利用set、out标签完成对三个属性的设置和显示
- [delphi函数]FileGetAttr、FileSetAttr 读取与设置文件属性
- DELPHI TreeView 文件目录树和 设置节点图标 完整
- stat命令--文件权限属性设置