Autor Beitrag
ByStones
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 92
Erhaltene Danke: 1

Windows XP
Delphi 2005
BeitragVerfasst: Mo 02.05.05 15:30 
Hi,

wie kopiere ich einfach eine Datei an einen anderen Ort ???
nach diesem prinzip:
ausblenden Delphi-Quelltext
1:
Copy('C:\test.dat','C:\test\');					


Bitte keine 100m Code, es muss nähmlich in ca. 2min eingebaut sein. :-)

//Edit:
Die Datei darf nicht mit DB.LoadFormFile geöffnet und mit DB.SaveToFile gespeichert werden !!!


Zuletzt bearbeitet von ByStones am Mo 02.05.05 15:39, insgesamt 1-mal bearbeitet
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 02.05.05 15:32 
Ich glaube, das heißt Copyfile (siehe OH)
bug0815
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 62

Win2000, Xp, Vista
Delphi 2006, 2009
BeitragVerfasst: Mo 02.05.05 15:33 
Man kann die Datei einfach incl. ihrem Pfad umbenennen.

Delphi-Syntax:
ausblenden Delphi-Quelltext
1:
function RenameFile(const OldName, NewName: string): Boolean;					


Zuletzt bearbeitet von bug0815 am Mo 02.05.05 15:37, insgesamt 1-mal bearbeitet
ByStones Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 92
Erhaltene Danke: 1

Windows XP
Delphi 2005
BeitragVerfasst: Mo 02.05.05 15:33 
user profile iconjasocul hat folgendes geschrieben:
Ich glaube, das heißt Copyfile (siehe OH)

Das oben hab ich mir nur ausgedacht, oder geht das wirklich ????
Es soll nur heißen, dass der Code keine 100 Zeilen lang sein soll !!!!!
:roll: :lol: :lol: 8) 8)
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 02.05.05 15:36 
Das heißt wirklich CopyFile und ist eine API-Funktion.
ByStones Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 92
Erhaltene Danke: 1

Windows XP
Delphi 2005
BeitragVerfasst: Mo 02.05.05 15:37 
user profile iconbug0815 hat folgendes geschrieben:
Man kann die Datei einfach incl. ihren Pfad umbenennen.

Delphi-Syntax:
ausblenden Delphi-Quelltext
1:
function RenameFile(const OldName, NewName: string): Boolean;					


Sie muss kopiert werden !!!!
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 02.05.05 15:39 
So, aus meiner Bilbiothek:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
function DateiKopieren(Quelle : String; Ziel : String) : Boolean;
var
  pQuelle, pZiel : Array [0..120of Char;
  OK : Boolean;
begin
  OK := False;
  StrPCopy(pQuelle, Quelle);
  StrPCopy(pZiel, Ziel);
  CopyFile(pQuelle, pZiel, OK);
  Result := OK;
end;
ByStones Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 92
Erhaltene Danke: 1

Windows XP
Delphi 2005
BeitragVerfasst: Mo 02.05.05 15:46 
user profile iconjasocul hat folgendes geschrieben:
So, aus meiner Bilbiothek:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
function DateiKopieren(Quelle : String; Ziel : String) : Boolean;
var
  pQuelle, pZiel : Array [0..120of Char;
  OK : Boolean;
begin
  OK := False;
  StrPCopy(pQuelle, Quelle);
  StrPCopy(pZiel, Ziel);
  CopyFile(pQuelle, pZiel, OK);
  Result := OK;
end;


Das ist kompakt, tscheck ich aber net !!!
Muss ich:
ausblenden Delphi-Quelltext
1:
pQuelle := 'C:\...';					


oder wie ????
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Mo 02.05.05 15:50 
ausblenden Delphi-Quelltext
1:
  copyfile(PChar('C:\test.dat'),PChar('C:\test\test.dat'),False);					

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.


Zuletzt bearbeitet von chrisw am Mo 02.05.05 15:54, insgesamt 1-mal bearbeitet
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 02.05.05 15:52 
Du weist aber schon, was eine Funktion und Parameter sind, oder?
Falls nicht, fehlen dir essentielle Grundlagen.
Du kannst diese Funktion benutzen und dich später damit auseinandersetzen. Bisher hat die Funktion bei mir immer funktioniert.
huhn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 272
Erhaltene Danke: 1

WIN XP
D7Pers
BeitragVerfasst: Mo 02.05.05 16:02 
Ausm kopf!
ein opendialog und ein savedialog auf die form ziehen!
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure button1.click(blabla);
var DataFile:TMemoryStream;
begin
if opendialog1.execute and savedialog1.execute then
  begin
    try
      DataFile:=TMemoryStream.Create;         //Copy File
      DataFile.LoadFromFile(od.filename);
      DataFile.SaveToFile(sd.filename);
    finally
      DataFile.Free;
    end;
  end;
end;

mfg huhn

_________________
Quod Erat Demonstrandum-Was zu beweisen war! *THX to Chrissivo!*


Zuletzt bearbeitet von huhn am Mo 02.05.05 16:27, insgesamt 1-mal bearbeitet
MathiasSimmack
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 02.05.05 16:08 
user profile iconjasocul hat folgendes geschrieben:
Du kannst diese Funktion benutzen und dich später damit auseinandersetzen. Bisher hat die Funktion bei mir immer funktioniert.

Gib am besten ein Beispiel. Ich weiß, dass das nervt, aber es gibt solche Leute, die fummeln in den Funktionen rum und wundern sich dann, warum hinterher gar nichts mehr geht. :roll:


@huhn: Klappt nicht, weil du was vergessen hast. Den Kopf noch mal anstrengen. ;)
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 02.05.05 16:30 
@MathiasSimmack:
Er wollte was schnelles in 3 Minuten haben. Da nehme ich mir nicht die Zeit ein Tutorial für den Aufruf eine Funktion zu schreiben :twisted:

Trotzdem hier ein Beispiel, wie man die Funktion aufruft:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
if DateiKopieren('C:\test.dat','C:\test\test.dat'then
  ShowMessage('Kopie erfolgreich')
else
  ShowMessage('Kopie nicht erfolgreich');


Die Funktion StrPCopy kann man in der OH nachlesen. Die ist erforderlich, da API-Parameter vom Typ PChar sind, ich in der Funktion aber Strings als Parameter übergebe.
huhn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 272
Erhaltene Danke: 1

WIN XP
D7Pers
BeitragVerfasst: Mo 02.05.05 16:31 
uuppps !
so ein mischgeschickt :oops:
naja ich nehm halt immer od und sd für die dialoge
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure TForm1.Button1Click(Sender: TObject);
var DataFile:TMemoryStream;
begin
if opendialog1.execute and savedialog1.execute then
  begin
    try
      DataFile:=TMemoryStream.Create;         //Copy File
      DataFile.LoadFromFile(opendialog1.filename);
      DataFile.SaveToFile(savedialog1.filename);
    finally
      DataFile.Free;
    end;
  end;
end;

so des is getestet und funktioniert!
mfg huhn

_________________
Quod Erat Demonstrandum-Was zu beweisen war! *THX to Chrissivo!*
huhn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 272
Erhaltene Danke: 1

WIN XP
D7Pers
BeitragVerfasst: Mo 02.05.05 16:35 
ich hab des noch von Mutze1 gefunden:
ausblenden volle Höhe Delphi-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:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
// Copies the passed file
//
// Parameters
//   OrgFN     - The original filename (the existing file to copy)
//   CopyFN    - The destination filename
//             - returns the status of the operation
// Return Value List
//   true : if operation is completed successfully
//   false: if any error occured
// Remarks
//   The function won't test the existence of the paths or if the
//   destination file exists and is writeable.
Function FileCopy(Const OrgFN, CopyFN : AnsiString) : Boolean;
Var
  InFile,
  OutFile   : TFileStream;
Begin
  InFile  := TFileStream.Create(OrgFN, fmOpenRead Or fmShareDenyNone);
  Try
    Try
      OutFile := TFileStream.Create(CopyFN, fmCreate);
      Try
        OutFile.CopyFrom(InFile, 0);
        Result := True;
      Except
        FreeAndNil(OutFile);
        FreeAndNil(InFile);
        Result := False;
      End;
    Except
      If Assigned(InFile) Then
        FreeAndNil(InFile);
      If Assigned(OutFile) Then
        FreeAndNil(OutFile);
      Result := False;
    End;
  Finally
    If Assigned(InFile) Then
      FreeAndNil(InFile);
    If Assigned(OutFile) Then
      FreeAndNil(OutFile);
  End;
End;

hier wird direkt kopiert ohne die datei in den arbeitsspeicher zu lesen.

_________________
Quod Erat Demonstrandum-Was zu beweisen war! *THX to Chrissivo!*
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 02.05.05 17:00 
user profile iconjasocul hat folgendes geschrieben:

Die Funktion StrPCopy kann man in der OH nachlesen. Die ist erforderlich, da API-Parameter vom Typ PChar sind, ich in der Funktion aber Strings als Parameter übergebe.

Ist aber unnötig, mit der Kompilermagic reicht ein einfacher Cast nach PChar.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 02.05.05 17:05 
Stimmt. Die Funktion ist aber schon ein paar Jährchen alt. Da hatte ich noch nicht soviel Erfahrung mit der API.
Sollte ich wirklich mal anpassen. :oops: