아래는 화일 다루는 예제를 몇가지 만들어 본 것입니다..
이름 변경은 System.Rename을 참고 하세요..
From 류..
---------
Function EraseFile(FileName:String):Boolean;
Var
EFile : File;
Begin
AssignFile(EFile, FileName);
Try
Erase(EFile);
Except
End;
Result:= not FileExists(FileName);
End;
Procedure EraseFiles(FileName:String);
Var
EFile : File;
stDir : String;
FResult : Integer;
FindRec : TSearchRec;
Begin
stDir:= FileName;
stDir:= ExtractFileDir(stDir);
If Length(stDir) > 0 then
If stDir[Length(stdir)] <> '\' then stDir:= stDir+'\';
FResult:= FindFirst(FileName, faAnyFile, FindRec);
While FResult = 0 Do
Begin
If (FindRec.Name <> '.') and
(FindRec.Name <> '..') then
Begin
AssignFile(EFile, stDir+FindRec.Name);
Try
Erase(EFile);
Except
End;
End;
FResult:= FindNext(FindRec);
End;
End;
Function CopyFile32(Source,Target:String):Integer;
Var
Sfs, Tfs : TFileStream;
Begin
Result:= 0;
If File_Size(Source) = 0 then
Begin
Result:= 3;
Exit;
End;
Try
Sfs:= TFileStream.Create(Source, fmOpenRead);
Except
on EStreamError do Result:= 1;
End;
Try
Tfs:= TFileStream.Create(Target, fmCreate);
Except
on EStreamError do Result:= 2;
End;
Tfs.CopyFrom(Sfs, Sfs.Size);
Sfs.Destroy;
Tfs.Destroy;
End;
Function CopyFile(Source,Target:String):Integer;
Var
RRead : Integer;
SFile, TFile : Integer;
Buffer : Packed Array [1..1024] of Byte;
Begin
Result:= 0;
If File_Size(Source) = 0 then Result:= 3
Else
Begin
SFile:= FileOpen(Source, fmOpenRead);
TFile:= FileCreate(Target);
End;
If SFile <= 0 then Result:= 1;
If TFile <= 0 then Result:= 2;
If Result = 0 then
Begin
RRead:= FileRead(SFile, Buffer, 1024);
While RRead > 0 Do
Begin
FileWrite(TFile, Buffer, RRead);
RRead:= FileRead(SFile, Buffer, 1024);
End;
FileSetAttr(Target, FileGetAttr(Source));
FileSetDate(TFile, FileGetDate(SFile));
FileClose(TFile);
FileClose(SFile);
End;
End;
Procedure CopyFiles32(SPath,TPath,Source:String);
Var
FResult : Integer;
FindRec : TSearchRec;
Begin
If SPath[Length(SPath)] <> '\' then SPath:= SPath + '\';
If TPath[Length(TPath)] <> '\' then TPath:= TPath + '\';
FResult:= FindFirst(SPath+Source, faAnyFile, FindRec);
While FResult = 0 Do
Begin
If (FindRec.Name <> '.') and
(FindRec.Name <> '..') then
CopyFile32(SPath+FindRec.Name, TPath+FindRec.Name);
FResult:= FindNext(FindRec);
End;
End;
Procedure CopyFiles(SPath,TPath,Source:String);
Var
FResult : Integer;
FindRec : TSearchRec;
Begin
If SPath[Length(SPath)] <> '\' then SPath:= SPath + '\';
If TPath[Length(TPath)] <> '\' then TPath:= TPath + '\';
FResult:= FindFirst(SPath+Source, faAnyFile, FindRec);
While FResult = 0 Do
Begin
If (FindRec.Name <> '.') and
(FindRec.Name <> '..') then
CopyFile(SPath+FindRec.Name, TPath+FindRec.Name);
FResult:= FindNext(FindRec);
End;
End;
|