Autor Beitrag
christoph
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28

Win XP(SPack1),Win 2000(Spack3)
Delphi 6(Spack2)
BeitragVerfasst: Sa 22.02.03 17:02 
Hallo mal ne Frage zu TSearchrec....

Ich möchte alle DatenDateien aus meinem Programm mit Endung'*.cst)
in einen Unterordner namens BackUp kopieren...
Nzur leider klappt es nicht mit diesem Code....



ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
procedure BackupData;
var
a,b,PathAlt,PathNeu,AppDir : string;
SearchRec : TSearchRec;
begin
//////////////////////////////////////////////////////////////////////////////////////
///Verzeichnis erzeugen aus Datum und Uhrzeit;
a :=Datetostr(Date)+' - ' + Timetostr(Time);
b:= CstReplaceChar(a,':','_');// Timezeichen ':' werden in '_' umgewandelt
If not DirectoryExists(ExtractFilepath(Application.Exename)+'\Data\Backup'+b) then
ForceDirectories(ExtractFilepath(Application.Exename)+'\Data\Backup\'+b);
//////////////////////////////////////////////////////////////////////////////////////
AppDir :=ExtractFilepath(Application.Exename)+'\Data\*.*';
PathAlt:=ExtractFilepath(Application.Exename)+'\Data\Backup\';
PathNeu:=ExtractFilepath(Application.Exename)+'\Data\Backup\'+b;
If Findfirst (AppDir,faAnyFile,SearchRec) = 0 then begin
repeat
copyFile(PChar(PathAlt+SearchRec.Name),Pchar(PathNeu+SearchRec.Name),False);
until FindNext(Searchrec) <> 0;
copyFile(PChar(PathAlt+SearchRec.Name),Pchar(PathNeu+SearchRec.Name),False);
end;
end;





Vielen Dank
Gruss
Chris
Fred Ferkel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 87



BeitragVerfasst: Sa 22.02.03 17:51 
bis wohin klappts denn?? wird z.B. das unterverzeichnis noch richtig erzeugt?
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Sa 22.02.03 18:08 
Hallo
ausblenden Quelltext
1:
PathAlt:=ExtractFilepath(Application.Exename)+'\Data\Backup\';					

wenn du mal hier einen Breakpoint gesetzt hättest und "Appdir" überprüft hättest, wüßtest du die antwort schon.
extractfilepath hat im Gegensatz zu extractfiledir (siehe OH) bereits einen \ am Ende. Mit deiner zuweisung hast du dann 2 \ in deinem String.

den rest habe ich nur kurz überfolgen:
- irgendwie fehlt ein findclose
- mach dich mal über SHFileoperation schlau

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
christoph Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28

Win XP(SPack1),Win 2000(Spack3)
Delphi 6(Spack2)
BeitragVerfasst: Sa 22.02.03 19:04 
Fehler gefunden.....Mit Dem folgenden Code funzt es



ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
procedure BackupData;
var
a,PathAlt,PathNeu,AppDir : string;
SearchRec : TSearchRec;
begin
//////////////////////////////////////////////////////////////////////////////////////
///Verzeichnis erzeugen aus Datum und Uhrzeit icl. nicht erlaubte Zeichen ersetzen;
a:= CstReplaceChar(Datetostr(Date)+' - ' + Timetostr(Time),':','_');
If not DirectoryExists(ExtractFilepath(Application.Exename)+'Data\Backup'+a) then
ForceDirectories(ExtractFilepath(Application.Exename)+'Data\Backup\'+a);
//////////////////////////////////////////////////////////////////////////////////////
AppDir :=ExtractFilepath(Application.Exename)+'Data\*.cst';
PathAlt:=ExtractFilepath(Application.Exename)+'Data\';
PathNeu:=ExtractFilepath(Application.Exename)+'Data\Backup\'+a;
If Findfirst (AppDir,faAnyFile,SearchRec) = 0 then begin
repeat
CopyFile(PChar(PathAlt+'\'+SearchRec.Name),PChar(Pathneu+'\'+SearchRec.Name),false);
until FindNext(Searchrec) <> 0;
CopyFile(PChar(PathAlt+'\'+SearchRec.Name),PChar(Pathneu+'\'+SearchRec.Name),false);
FindClose(SearchRec);
end;
end;


Gruss
Chris