声明:function FileSetAttr ( const FileName : string; Attributes : Integer ) : Integer;
{创建一个文本文件,设置为只读与系统,显示文件属性}
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; 程序运行结果: |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论