其他分享
首页 > 其他分享> > IOUtils单元下的Tfile

IOUtils单元下的Tfile

作者:互联网

TFile = record
    //创建文件,返回TFileStream,需调用TFileStream.Free才会写入文件系统
     function Create(const Path: string): TFileStream; overload;  
     function Create(const Path: string; const BufferSize: Integer): TFileStream; overload; 
    //在文件的后面添加内容
     procedure AppendAllText(const Path, Contents: string); overload; 
     procedure AppendAllText(const Path, Contents: string; const Encoding: TEncoding); overload; 
    //打开一个文件的TStreamWriter,然后对其进行内容添加的操作
     function AppendText(const Path: string): TStreamWriter; 
    //复制文件
     procedure Copy(const SourceFileName, DestFileName: string); overload;  
     procedure Copy(const SourceFileName, DestFileName: string; const Overwrite: Boolean); overload; 
     function CreateSymLink(const Link, Target: string): Boolean; 
    //创建文本文件,返回TStreamWriter
     function CreateText(const Path: string): TStreamWriter; 
    //对文件进行加密解密
     procedure Encrypt(const Path: string);
     procedure Decrypt(const Path: string); 
    //删除文件
     procedure Delete(const Path: string); 
    //判断文件是否存在
     function Exists(const Path: string; FollowLink: Boolean = True): Boolean;  
    //获得文件的属性
     function GetAttributes(const Path: string; FollowLink: Boolean = True): TFileAttributes;  
     function GetCreationTime(const Path: string): TDateTime;  
     function GetCreationTimeUtc(const Path: string): TDateTime;  
     function GetLastAccessTime(const Path: string): TDateTime;  
     function GetLastAccessTimeUtc(const Path: string): TDateTime;  
     function GetLastWriteTime(const Path: string): TDateTime;  
     function GetLastWriteTimeUtc(const Path: string): TDateTime;  
     function GetSymLinkTarget(const FileName: string; var SymLinkRec: TSymLinkRec): Boolean; overload; 
     function GetSymLinkTarget(const FileName: string; var TargetName: string): Boolean; overload; 
    //移动文件
     procedure Move(SourceFileName, DestFileName: string); 
    //打开存在的文件
     function Open(const Path: string; const Mode: TFileMode): TFileStream; overload;  
     function Open(const Path: string; const Mode: TFileMode; const Access: TFileAccess): TFileStream; overload;  
     function Open(const Path: string; const Mode: TFileMode; const Access: TFileAccess;
        const Share: TFileShare): TFileStream; overload; 
     function OpenRead(const Path: string): TFileStream; 
     function OpenText(const Path: string): TStreamReader; 
     function OpenWrite(const Path: string): TFileStream; 
    //读取文件内容
     function ReadAllBytes(const Path: string): TBytes; 
     function ReadAllLines(const Path: string): TStringDynArray; overload; 
     function ReadAllLines(const Path: string; const Encoding: TEncoding): TStringDynArray; overload; 
     function ReadAllText(const Path: string): string; overload;  
     function ReadAllText(const Path: string; const Encoding: TEncoding): string; overload;  
    //替换文件,替换后,SourceFileName被删除,DestinationFileName备份为DestinationBackupFileName

     procedure Replace(const SourceFileName, DestinationFileName,
        DestinationBackupFileName: string); overload; 
     procedure Replace(SourceFileName, DestinationFileName,
        DestinationBackupFileName: string; const IgnoreMetadataErrors: Boolean);
        overload; 
//设置文件属性
     procedure SetAttributes(const Path: string;
        const Attributes: TFileAttributes);  
     procedure SetCreationTime(const Path: string;
        const CreationTime: TDateTime);  
     procedure SetCreationTimeUtc(const Path: string;
        const CreationTime: TDateTime);  
     procedure SetLastAccessTime(const Path: string;
        const LastAccessTime: TDateTime);  
     procedure SetLastAccessTimeUtc(const Path: string;
        const LastAccessTime: TDateTime);  
     procedure SetLastWriteTime(const Path: string;
        const LastWriteTime: TDateTime);  
     procedure SetLastWriteTimeUtc(const Path: string;
        const LastWriteTime: TDateTime);  
    //写入文件内容
     procedure WriteAllBytes(const Path: string; const Bytes: TBytes); 
     procedure WriteAllLines(const Path: string;
        const Contents: TStringDynArray); overload;  
     procedure WriteAllLines(const Path: string;
        const Contents: TStringDynArray; const Encoding: TEncoding); overload; 
     procedure WriteAllText(const Path, Contents: string); overload; 
     procedure WriteAllText(const Path, Contents: string;
        const Encoding: TEncoding); overload; 
  end;

 

标签:function,const,string,Tfile,overload,IOUtils,procedure,Path,单元
来源: https://www.cnblogs.com/luohq001/p/13056142.html