- Jak skopiowac plik.txt z C : \ na D : \
- Jak przenieść plik.txt z C : \ na D : \
- Jak usunąć plik?
- Jak utworzyć plik.txt?
- Jak utworzyć katalog?
- Jak usunąć katalog?
Dzieki za odp. ! [browar]
Dzieki za odp. ! [browar]
1, 2, 3 : http://4programmers.net/view.html?id=7
4 : AssignFile, Rewrite (i Detox odczep się ;) )
5 : MkDir
6 : RmDir
type
EInvalidDest = class(EStreamError);
EFCantMove = class(EStreamError);
const
SInvalidDest = 'Destination %s does not exist';
SFCantMove = 'Cannot move file %s';
procedure CopyFile(const FileName, DestName: string);
var
CopyBuffer: Pointer; { buffer for copying }
BytesCopied: Longint;
Source, Dest: Integer; { handles }
Len: Integer;
Destination: TFileName; { holder for expanded destination name }
const
ChunkSize: Longint = 8192; { copy in 8K chunks }
begin
Destination := ExpandFileName(DestName); { expand the destination path }
if HasAttr(Destination, faDirectory) then { if destination is a directory... }
begin
Len := Length(Destination);
if Destination[Len] = '' then
Destination := Destination + ExtractFileName(FileName) { ...clone file name }
else
Destination := Destination + '' + ExtractFileName(FileName); { ...clone file name }
end;
GetMem(CopyBuffer, ChunkSize); { allocate the buffer }
try
Source := FileOpen(FileName, fmShareDenyWrite); { open source file }
if Source < 0 then raise EFOpenError.CreateFmt(SFOpenError, [FileName]);
try
Dest := FileCreate(Destination); { create output file; overwrite existing }
if Dest < 0 then raise EFCreateError.CreateFmt(SFCreateError, [Destination]);
try
repeat
BytesCopied := FileRead(Source, CopyBuffer^, ChunkSize); { read chunk }
if BytesCopied > 0 then { if we read anything... }
FileWrite(Dest, CopyBuffer^, BytesCopied); { ...write chunk }
until BytesCopied < ChunkSize; { until we run out of chunks }
finally
FileClose(Dest); { close the destination file }
end;
finally
FileClose(Source); { close the source file }
end;
finally
FreeMem(CopyBuffer, ChunkSize); { free the buffer }
end;
end;
(mozna dodac progressbar'a)
(jest to fragment :))
2. skopiowac i usunac plik "zrodlowy"
3. deletefile
Dzieki Berl !