Board logo

標題: [Delphi] 資料夾及檔案處理 [打印本頁]

作者: admin    時間: 2012-4-7 22:59     標題: [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;




歡迎光臨 How2Do (http://forum.how2do.com.hk/) Powered by Discuz! 7.2