Autor Beitrag
derDoc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Mo 17.02.03 19:55 
Kann mir jemand sagen, wie ich eine Datei in ein anderes Verzeichnis kopieren kann? Unter Windows gibt es die API-Routine CopyFile, gibt es dazu auch ein Linux Äquivalent?

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
AndyB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1173
Erhaltene Danke: 14


RAD Studio XE2
BeitragVerfasst: Mo 17.02.03 21:42 
Nicht das ich wüsste. Du hast dafür aber mehrere Möglichkeiten es selbst zu machen.
Die einfachst zu programmierende ist:
ausblenden Quelltext
1:
Libc.system(PChar(Format('cp "%s" "%s"', [QuellDatei, ZielDatei]));					

So nebenbei: Da unter Linux eine Menge von nützlichen Programmen schon vorhanden ist und man das Rad nicht immer neu erfinden will, was auch Fehler mit sich bringt, die bei den vorhandenden Programmen über Jahre hinweg entfernt wurden, ruft man diese direkt vom eigenen Programm aus auf.


Andereseits kannst du mit TFileStream die Daten kopieren.

(Ungetestet:)
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
function CopyFile(const SourceFile, DestFile: string; AllowOverwrite: Boolean): Boolean;
var
  Source, Dest: TFileStream;
  statBuf: Libc.TStatBuf;
  t: Libc.utimbuf;
begin
  Result := False;
  if (FileExists(DestFile)) and (not AllowOverwrite) then Exit;
  Result := True;
  if Libc.stat(PChar(SourceFile), statBuf) = -1 then
    raise Exception.Create('Error obtaining file information');

  Source := nil;
  Dest := nil;
  try
    Source := TFileStream.Create(SourceFile, fmOpenRead or fmShareDenyWrite);
    Dest := TFileStream.Create(SourceFile, fmCreate, statBuf.st_mode);

    Dest.CopyFrom(Source, 0);
  finally
    Dest.Free;
    Source.Free;
  end;
 // set time
  t.actime := statBuf.st_atime;
  t.modtime := stateBuf.st_mtime;
  Libc.utime(PChar(DestFile), t);
end;

_________________
Ist Zeit wirklich Geld?
derDoc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Mo 17.02.03 21:59 
Danke AndyB, ich werde das mal testen.

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.