SysUtils下的文件类函数/过程

1、不支持通配符的函数:

function FileExists(const FileName: string; FollowLink: Boolean = True): Boolean;
function DirectoryExists(const Directory: string; FollowLink: Boolean = True): Boolean;
function DeleteFile(const FileName: string): Boolean;
function RemoveDir(const Dir: string): Boolean;
function GetCurrentDir: string;
function SetCurrentDir(const Dir: string): Boolean;
function RenameFile(const OldName, NewName: string): Boolean;
function CreateDir(const Dir: string): Boolean;//如没有上层目录则失败
function ForceDirectories(Dir: string): Boolean;//如没有上层目录则强制建立上层目录;
function RemoveDir(const Dir: string): Boolean;//删除空目录,且只能一层一层的删除
function DiskFree(Drive: Byte): Int64;
function DiskSize(Drive: Byte): Int64;
function FileSearch(const Name, DirList: string): string;//DirList是路径列表,各路径之间以“;”分割。此函数在路径列表下查找文件,查找到就返回文件的完整路径,如果文件在当前路径下存在,则只返回文件名且文件名不含路径;
//下面四个函数是针对当前目录下的判断
function LocaleFileExists(const FileName: string): Boolean;//判断文件是否存在
function GetLocaleFile(const FileName: string): string;//得到文件的全路径
function LocaleDirectoryExists(const Directory: string): Boolean;//判断当前路径下是否存在子目录
function GetLocaleDirectory(const Directory: string): String;//获得子目录的路径

2、支持通配符的几个函数/过程:

定义了下面这个结构(只保留了windows的元素):

TSearchRec = record
  private
    function GetTimeStamp: TDateTime;
  public
    Time: Integer platform deprecated;
    Size: Int64;
    Attr: Integer;
    Name: TFileName;
    ExcludeAttr: Integer;
    FindHandle: THandle platform;
    FindData: TWin32FindData platform;
    property TimeStamp: TDateTime read GetTimeStamp;
  end;
function FindFirst(const Path: string; Attr: Integer;  var F: TSearchRec): Integer;
//查找第一个符合条件的文件,支持通配符,找到则将找到的文件信息存储到F中,并返回1.
  //Attr 中的属性是一个整数值, 可能的值有:
  //faReadOnly  1   只读文件
  //faHidden    2   隐藏文件
  //faSysFile   4   系统文件
  //faVolumeID  8   卷标文件
  //faDirectory 16  目录文件
  //faArchive   32  归档文件
  //faSymLink   64  链接文件
  //faAnyFile   63  任意文件
  //Path的值也可以使用?通配符,好像只支持7个?, 如果没有条件就是*, 譬如: C:*
  //实际使用中还应该在 repeat 中提些条件, 譬如判断如果是文件夹就递归搜索等等
function FindNext(var F: TSearchRec): Integer;
procedure FindClose(var F: TSearchRec);//这个过程用于终止findfirst和findnext,并释放分配给F的内存。每个findfirst和/或findnext的最终都应该且必须以findclose结束。

3、用于获得文件时间、属性等的函数/过程:

function FileGetDate(Handle: THandle): Integer;
function FileGetDateTimeInfo(const FileName: string;
  out DateTime: TDateTimeInfoRec; FollowLink: Boolean = True): Boolean;
function FileSetDate(const FileName: string; Age: Integer): Integer;
function FileSetDate(Handle: THandle; Age: Integer): Integer;
function FileGetAttr(const FileName: string; FollowLink: Boolean = True): Integer;
function FileSetAttr(const FileName: string; Attr: Integer; FollowLink: Boolean = True): Integer; 
function FileIsReadOnly(const FileName: string): Boolean;
function FileSetReadOnly(const FileName: string; ReadOnly: Boolean): Boolean;
function DeleteFile(const FileName: string): Boolean;
function ChangeFileExt(const FileName, Extension: string): string; //修改文件扩展名

4、分解文件信息的函数/过程

function ExtractFilePath(const FileName: string): string;
function ExtractFileDir(const FileName: string): string;
function ExtractFileDrive(const FileName: string): string;
function ExtractFileName(const FileName: string): string;
function ExtractFileExt(const FileName: string): string;
function ExpandFileName(const FileName: string): string;//获得文件的完整信息,用.或者".."来表示的目录层次也将转换为具体的字符形式的目录。
原文地址:https://www.cnblogs.com/luohq001/p/12917705.html