第六章文件管理三内容摘要:

= FileGetAttr(AFileName)。 := (Attributes and faReadOnly) = faReadOnly。 := (Attributes and faArchive) = faArchive。 := (Attributes and faSysFile) = faSysFile。 := (Attributes and faHidden) = faHidden。 if ShowModal idCancel then begin NewAttributes := Attributes。 if then NewAttributes := NewAttributes or faReadOnly else NewAttributes := NewAttributes and not faReadOnly。 if then NewAttributes := NewAttributes or faArchive else NewAttributes := NewAttributes and not faArchive。 if then NewAttributes := NewAttributes or faSysFile else NewAttributes := NewAttributes and not faSysFile。 if then NewAttributes := NewAttributes or faHidden else NewAttributes := NewAttributes and not faHidden。 if NewAttributes Attributes then FileSetAttr(AFileName, NewAttributes)。 end。 end。 end。 以上过程中用到的函数 FileDataTime 在 fmxutils 单元中定义,返回一个TDatatime 类型的变量。 function FileDateTime(const FileName: String):。 begin Result := FileDateToDateTime(FileAge(FileName))。 end。 其它文件管理功能的实现 在子窗口的 Function 菜单中,定义了一些其它的文件管理功能: ● Search :查找一个给定名字的文件,若存在则显示该文件属性 ● Disk View :显示当前驱动器的大小和剩余空间 ● View type :确定显示文件的类型 文件查找 当用户单击 Search 菜单项时,程序弹出一个对话框 (如图 ),要求输入待查找的文件名和查找路径。 文件名可以是通配符。 当用户确认后程序显示第一个匹配文件的属性 (如图 )。 查找不到匹 配文件则给出相应的信息。 在实现这一功能的最初设计中,我试图使用 FileSearch 函数,这个函数允许在多个不同路径中查找。 但可惜的是:也许由于系统设计者的失误,这个函数并没有返回它应该返回的东西 (第一个匹配文件的全路径名 ),而是仍把输入的匹配符返回。 没有办法我只能再次使用 FindFirst,这个函数的特性在 节中已进行了介绍。 下面是这一功能的实现代码。 procedure (Sender: TObject)。 var SearchForm: TSearchForm。 FileAttrForm: TFileAttrForm。 FindIt,path: String。 SearchRec: TSearchRec。 Return: Integer。 begin SearchForm := (self)。 with SearchForm do begin := 39。 39。 :=。 if (ShowModal idCancel) and ( 39。 39。 ) and ( 39。 39。 ) then begin FindIt := +39。 \39。 +。 Return := FindFirst(FindIt,faAnyFile,SearchRec)。 if Return 0 then FindIt := 39。 39。 else FindIt := ExpandFileName()。 end。 if FindIt = 39。 39。 then MessageDlg(39。 Cannot find the file in current directory.39。 , mtWarning, [mbOk], 0) else begin Path := ExtractFilePath(FindIt)。 FindIt := ExtractFileName(FindIt)。 FileAttrForm := (self)。 ShowFileAttr(FileAttrForm,FindIt,Path)。 end。 end。 end。 显示磁盘信息 当用户单击 Disk View菜单项时,将弹出一个 TDiskViewForm类型的对话框,用来显示当前磁盘的信息 磁盘信息的获取是在 DiskViewForm 中 DriveEdit 编辑框的OnChange 事件处理过程中实现的。 procedure (Sender: TObject)。 var dr: Byte。 Free,Total: LongInt。 begin Free := DiskFree(0)。 Total := DiskSize(0)。 := IntToStr(Free)+ 39。 bytes.39。 := IntToStr(Total) + 39。 bytes.39。 end。 DiskFree、 DiskSize 带参数为 0 表示当前驱动器。 读者可以很容易把它改成按用户输入显示磁盘信息的情况。 DiskViewForm 中的三个编辑框设计时都令 ReadOnly 为 True。 改变显示文件的类型 改变显示文件的类型事 实上是设置 FileList 的 Mask 属性。 我们利用一个标准的 InputBox 输入文件的匹配字符串。 而后利用 Update 方法更新 FileList。 procedure (Sender: TObject)。 var FileMask: String。 begin FileMask := InputBox(39。 File type39。 ,39。 Input File type For View :39。 ,)。 If FileMask = 39。 39。 then FileMask := 39。 *.*39。 := FileMask。 CreateCap。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。