返回列表 發帖

[Delphi] 資料夾及檔案處理

uses Sysutils

Directories

======
Create a Directory :CreateDir('c:\path');
Remove a Directory : RemoveDir('c:\path') or RmDir('c:\path')
Change a Directory : ChDir('c:\path')
Current Directory : GetCurrentDir
Check if a Directory exists : if DirectoryExists('c:\path') then ...


Files
===
Rename a File : RenameFile('file1.txt', 'file2.xyz')
Delete a File : DeleteFile('c:\text.txt')
Move a File : MoveFile('C:\file1.txt','D:\file1.txt');
Copy a File :* CopyFile(Pchar(File1),PChar(File2),bFailIfExists)
Change a File's Extension : ChangeFileExt('test.txt', 'xls')
Check if a File exists : if FileExists('c:\filename.tst') then ...



The CopyFile function copies an existing file to a new file.


CopyFile(
  lpExistingFileName : PChar, // name of an existing file
  lpNewFileName : PChar,      // name of new file
  bFailIfExists : Boolean);   // operation if file exists

bFailIfExists:
  Specifies how this operation is to proceed if a file of the same name as
  that specified by lpNewFileName already exists.
  If this parameter is TRUE and the new file already exists, the function fails.
  If this parameter is FALSE and the new file already exists,
  the function overwrites the existing file and succeeds.
}

var
  
fileSource, fileDest: string;
begin
  
fileSource := 'C:\SourceFile.txt';
  fileDest := 'G:\DestFile.txt';
  CopyFile(PChar(fileSource), PChar(fileDest), False);
end;
Bill Tang     MSN:billtang@openplatform.com.hk
Openplatform Technology Co.,Ltd. 資訊坊科技有限公司  
無線工程施工、方案設計、無線產品、天饋材料、終端設備綜合供應商
Tel: 852-27491011  Fax: 852-81483532

返回列表