本文整理自网络,侵删。
delphi 部分操作文件函数
1、返回文件扩展名
function ExtractFileExt(const FileName: ): ;
2、返回文件名
function ExtractFileName(const FileName: ): ;
返回应用文件名
function ExtractFileName(ParamStr(0)): ;
返回应用路径
function ExtractFilePath(ParamStr(0)): ;
3、检测文件是否存在
function FileExists: Boolean;
4、查找目录中是否存在某文件
function FileSearch(const Name, DirList: ): ;
5、返回路径名
function ExpandFileName(const FileName: ): ;
6、返回文件大小
function FileSize(var F): Integer;
7、返回上上次I/O操作状态
function IOResult: Integer;
8、返回文件属性
function FileGetAttr(const FileName: ): Integer;
9、设置文件属性
function FileSetAttr(const FileName: ; Attr: Integer): Integer;
10、设置文件DOS日期戳
On Windows:
function FileSetDate(Handle: Integer; Age: Integer): Integer; overload;
Cross-platform:
function FileSetDate(const FileName: ; Age: Integer): Integer; overload;
11、返回文件DOS日期戳
function FileGetDate(Handle: Integer): Integer;
12、把Delphi日期格式转化为DOS日期格式
function DateTimeToFileDate(DateTime: TDateTime): Integer;
13、把DOS日期格式转化为Delphi日期格式
function FileDateToDateTime(FileDate: Integer): TDateTime;
14、 修改文件扩展名
function ChangeFileExt(const FileName, Extension: ): ;
15、删除文件
function DeleteFile(const FileName: ): Boolean; (SysUtils)
16、打开文件
function FileOpen(const FileName: ; Mode: LongWord): Integer;(SysUtils)返回为文件句柄
打开模式:fmOpenRead fmOpenWrite fmOpenReadWrite fmShareCompat fmShareExclusive fmShareDenyWrite fmShareDenyRead fmShareDenyNone
17、把光标定位到某点
function FileSeek(Handle, Off, Origin: Integer): Integer; overload;
function FileSeek(Handle: Integer; const Off: Int64; Origin: Integer): Int64; overload;
Off为偏移量
Origin为开始模式
Origin Action
0 The file poer is positioned Off s from the beginning of the file.
1 The file poer is positioned Off s from its current position.
2 The file poer is positioned Off s from the end of the file.
18、把文件读到缓冲区
function FileRead(Handle: Integer; var Buffer; Count: Integer): Integer;
19、关闭文件
procedure FileClose(Handle: Integer);
相关阅读 >>
Delphi xe ttask.waitforall/waitforany 一不小心会造成内存泄露
Delphi getforegroundwindow 与 getactivewindow 的区别
Delphi利用微软sapi实现语音控制(Delphi,tts,sr,灰色代码)_
Delphi 递归实现从m 个集合中 任取一个元素 生成组合
更多相关阅读请进入《Delphi》频道 >>