zoukankan      html  css  js  c++  java
  • delphi FileSetAttr 设置文件的属性转

    声明: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

  • 相关阅读:
    UTF8 GBK UTF8 GB2312 之间的区别和关系
    error
    adb
    没有在Manifest.xml中注册Activity
    office 2003打开2007版文件插件(附官方下载地址): compatibility pack for the 2007 office system
    R包MetaboAnalystR安装指南(Linux环境非root)
    R合并数据框有重复匹配时只保留第一行
    质谱行业介绍
    蛋白质组学数据分析——(1)原理
    [R报错] Kruskalwallis test 所有组的层次都必需是有限的
  • 原文地址:https://www.cnblogs.com/shuaixf/p/1742502.html
Copyright © 2011-2022 走看看