delphi:文件操作

1.复制  CopyFile

function CopyFile(lpExistingFileName, lpNewFileName: PChar; bFailIfExists: BOOL): BOOL; stdcall;

lpExistingFileName <源文件的全部路径>

lpNewFileName <目标文件的全部路径>

bFailIfExists  true:存在则覆盖文件,false相反

举例:

CopyFile('D:1.txt','D:2.txt',True);

CopyFile(pchar('D:1.txt'),pchar('D:2.txt'),True);


2. 创建 CreateFile

function CreateFile(lpFileName: PChar; dwDesiredAccess, dwShareMode: DWORD;
   lpSecurityAttributes: PSecurityAttributes; dwCreationDisposition, dwFlagsAndAttributes: DWORD;
   hTemplateFile: THandle): THandle; stdcall;

3. 关联 AssignFile(VarTxt, FileName);

AssignFile(VarTxt, FileName);

VarTxt 是变量, FileName是字符串

初始化读写有三种方式:
(1) Reset: 只读打开, 指针移到文件头;
(2) Rewrite: 创建新文件并打开, 只写;
(3) Append: 从尾部追加。

原文地址:https://www.cnblogs.com/huiy/p/12508667.html