kopiowanie, przenoszenie, usuwanie ...

0
  1. Jak skopiowac plik.txt z C : \ na D : \
  2. Jak przenieść plik.txt z C : \ na D : \
  3. Jak usunąć plik?
  4. Jak utworzyć plik.txt?
  5. Jak utworzyć katalog?
  6. Jak usunąć katalog?

Dzieki za odp. ! [browar]

0

1, 2, 3 : http://4programmers.net/view.html?id=7
4 : AssignFile, Rewrite (i Detox odczep się ;) )
5 : MkDir
6 : RmDir

0
  1. Oto przyklad ze zrodel delphi (DEMOS):
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

0

Dzieki Berl !

1 użytkowników online, w tym zalogowanych: 0, gości: 1