IOUtils 单元主要就是三个结构: TDirectory、TPath、TFile, 很有用; 下面是 TFile 的功能简介.
TFile.Exists();
TFile.Copy();
TFile.Move();
TFile.Delete();
TFile.Replace();
TFile.Create();
TFile.Exists();
//判断指定的文件是否存在
TFile.Copy();
//复制文件 var source,dest: string; begin TFile.Copy(source, dest); {不允许覆盖同名的文件} TFile.Copy(source, dest, True); {将覆盖同名的文件} end;
TFile.Move();
//移动文件 var source,dest: string; begin TFile.Move(source, dest); end;
TFile.Delete();
//删除文件
TFile.Replace();
//替换文件, dest 会备份在 bak, 复制 source 的内容到 dest 后, sourece 会被删除. var source,dest,bak: string; begin source := 'c:\temp\t1.txt'; dest := 'c:\temp\t2.txt'; bak := 'c:\temp\t3.txt'; TFile.Replace(source, dest, bak); {前两个文件必须存在} TFile.Replace(source, dest, bak, True); {忽略错误} end;
TFile.Create();
//建立文件并返回一个和文件关联的 TFileStream, 指定文件存在则覆盖 var buf: array[0..1023] of Byte; fs: TFileStream; begin {模拟一个缓冲区并填充} FillChar(buf, SizeOf(buf), 65); {使用返回的 TFileStream 写入流} fs := TFile.Create('c:\temp\test1.txt'); fs.Write(buf, Si