1、第七讲 文件管理,一、基本概念:,1. 文件:同一类型元素的有序集合,是内存与外设之间传输数据的通道。2.文件的组织与管理形式:驱动器:文件夹:文件:,二、Delphi7文件管理方式:,DriverComboBox or ShellComboBox,FilelistBox or ShellListView,DirectoryListBox or ShellTreeView,1. Win3.1选项卡上的文件管理组件 驱动器组合列表框(DriveComboBox)常用属性:DirList: 指定关联的目录列表框;Driver: 运行时属性目录列表框(DirectoryListBox)常用属性:Fi
2、leList: 指定关联的文件列表框DirLabel: 记录当前的目录路径(When the current directory changes in the directory list box, the change is reflected in the caption of the label.)Driver: 运行时属性Directory: 运行时属性,文件列表框(FileListBox): 常用属性:MultiSelect:Drive: 运行时属性Diretory: 运行时属性FileName: 运行时属性FileType: 显示文件的属性(默认ftNormal)FileEdit:
3、 set FileEdit to an edit control that displays the selected file from the file list box, as is commonly done in Open and Save dialog boxes.,type TFileAttr = (ftReadOnly, ftHidden, ftSystem, ftVolumeID, ftDirectory, ftArchive, ftNormal);TFileType = set of TFileAttr;,文件类型过滤组合列表框(FilterComboBox)常用属性:Fi
4、leList:set FileList to allow the filter combo box to limit which files are displayed in the FileListbox. Filter:To create the value of Filter for a single file type, follow these steps:1 Type some meaningful text to indicate the type of file. 2 Type a | character (vertical bar). 3 Type the file filt
5、er.Dont put in any spaces around the | character in the string.Heres an example:FilterComboBox1.Filter := Text files|*.TXT;FilterComboBox1-Filter = “Text files|*.TXT“;,To specify multiple file filters, extend the value of Filter, separating each file name/mask combination with a | character. Heres a
6、n example of two file filters that could be specified as the value of the Filter property:Text files (*.TXT)|*.TXT|Pascal files (*.PAS)|*.PAS“Text files (*.TXT)|*.TXT|C+ files (*.CPP)|*.CPP“,实例:,2 Samples选项卡上的文件管理组件,ShellTreeView组件: 常用属性: Root: ShellComboBox: ShellListView:ShellComboBox组件: 常用属性: She
7、llTreeView: ShellListView:,ShellListView组件:常用属性:ShellTreeView:ShellCombox:Viewstyle: Set ViewStyle to control the visual display of items in a list view. (vsIcon、vsList、vsSmallIcon、vsReport),实例:资源管理器,三、文件管理函数和过程:,功能:实现对文件的管理。删除文件文件重命名创建文件夹删除文件夹,function RenameFile(const OldName, NewName: string): Bo
8、olean;example:if not RenameFile(c:abc.bmp,abc.doc) thenshowmessage(Can not rename file!);function DeleteFile(const FileName: string): Boolean;Description:DeleteFile deletes the file named by FileName from the disk. If thefile cannot be deleted or does not exist, the function returns false.function FileExists(const FileName: string): Boolean;Description:FileExists returns true if the file specified by FileName exists. If the file does not exist, FileExists returns false,