Autor Beitrag
masteroffinalfantasy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

Win XP
Delphi 2005 Architect
BeitragVerfasst: Fr 19.05.06 10:54 
Hallo Leute :)

Ich hab da mal wieder ein Problem^^

Ich benutze folgene Funktion. das Problem ist, dass Ich eine Meldung bekomme, in der gesagt wird, dass der Dateiname zu lang wäre, dabei sind es mit Ordnerpfad keine 60 Zeichen... Gibt es eine Möglichkeit diese Blockade aufzuheben?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
function CopyDir(const fromDir, toDir: string): Boolean;
var
  fos: TSHFileOpStruct;
begin
  ZeroMemory(@fos, SizeOf(fos));
  with fos do
  begin
    wFunc  := FO_COPY;
    fFlags := FOF_FILESONLY;
    pFrom  := PChar(fromDir + #0);
    pTo    := PChar(toDir)
  end;
  Result := (0 = ShFileOperation(fos));
end;


Die Funktion rufe ich wiefolgt auf

ausblenden Delphi-Quelltext
1:
2:
3:
4:
var max:Integer;
[...]
if  CopyDir(inttostr(max),inttostr(max+1)+'\'then
[...]


Theoretisch sollen dabei alle Dateien aus einem Ordner mit der Bezeichnung max in den Ordner max+1 kopiert werden. Die Variable max wird vorher gesetzt...
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Fr 19.05.06 13:02 
Ich wüßte von keiner Blockade, magst du mal einen Beispielstring posten?
masteroffinalfantasy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

Win XP
Delphi 2005 Architect
BeitragVerfasst: Fr 19.05.06 13:07 
als beispiel:
Wenn max=1 ist dann sollte es ja so aussehen:

Kopiere Ordner '1\' in Ordner '2'.
Eine Beispieldatei wäre 'Max Mustermann.txt'
-->
'Dieser Dateiname ist für den Zielordner zulang.'
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Fr 19.05.06 13:14 
Hmm ja aber debugge mal und kontrolliere wie der String wirkich aussieht. Vielleicht macht ihm das Zeromemory zu schaffen? Denke da an Nullterminierung und so...
masteroffinalfantasy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

Win XP
Delphi 2005 Architect
BeitragVerfasst: Fr 19.05.06 13:41 
hmm also der String stimmt
Hier mal die genaue Meldung:
user defined image
Was auch merkwürdig ist, ist dass der Originalordner in den Zu Kopierenden Ordner reinkopiert wird, und nicht nur die Dateien (wenn sie denn kopiert werden würden)

Wenn ich dann z.B. auf 'Automatisch' drücke, dann läuft der Dialog weiter und es scheint, als ob die Daten kopiert werden,aber sie sind nicht im Zielordner
raiguen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 374

WIN 2000prof, WIN XP prof
D7EP, MSSQL, ABSDB
BeitragVerfasst: Fr 19.05.06 15:00 
Moin :9
Ich vermute mal, dass Du den Inhalt des Ordners 1 in den Ordner 2 kopieren möchtest :gruebel:
Probier mal folgendes:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
function CopyFiles(sQuellPfad, sZielPfad): boolean;
var
  fos : TSHFILEOPSTRUCT;
begin
    sQuellPfad := sQuellPfad + #0#0;
    sZielPfad := sZielPfad + #0#0;
    FillChar(SHFILEOPSTRUCT, SizeOf(fos), #0);
    fos.wnd := Application.Handle;
    fos.wFunc := FO_COPY;
    fos.pFrom := PAnsiChar(sQuellPfad);
    fos.pTo := PAnsiChar(sZielPfad);
    fos.fFlags := FOF_FILESONLY;
    Result := (SHFileOperation(fos) = 0);
end;

Aufruf mit
ausblenden Delphi-Quelltext
1:
  if CopyFiles('Spielerdaten\1\'+QuotedStr('max mustermann.txt'), 'Spielerdaten\2'then ...					

Bei Dateinamem mit Leerzeichen empfiehlt es sich immer, diese in "" zu setzen ->QuotedStr(Dateiname)

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt
masteroffinalfantasy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

Win XP
Delphi 2005 Architect
BeitragVerfasst: Fr 19.05.06 18:33 
hi
Danke das du versuchst mir zu helfen :)
also ich hab das mal eingebaut.Jedoch
scheinen in der Funktion Fehler zu sein.
Also ich hab mal den Filetyp string im Header eingebaut, aber jetzt meckert der bei FIllChar(SHFILEOPSTRUCT,SizeOF(fos),#0) rum. Der Compiler möchte bei dem ersten Komma ne Klammer O_o
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
function CopyFiles( sQuellPfad, sZielPfad:string): boolean;
var
  fos : TSHFILEOPSTRUCT;
begin
    sQuellPfad := sQuellPfad + #0#0;
    sZielPfad := sZielPfad + #0#0;
    FillChar(SHFILEOPSTRUCT,SizeOf(fos), #0);
    fos.wnd := Application.Handle;
    fos.wFunc := FO_COPY;
    fos.pFrom := PAnsiChar(sQuellPfad);
    fos.pTo := PAnsiChar(sZielPfad);
    fos.fFlags := FOF_FILESONLY;
    Result := (SHFileOperation(fos) = 0);
end;


Mein Aufruf sieht jetzt so aus:
ausblenden Delphi-Quelltext
1:
if CopyFiles('Spielerdaten\'+inttostr(max)+'\'+QuotedStr(spielernamena[i]+'.txt'),'Spielerdaten\'+inttostr(max+1)) then					
raiguen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 374

WIN 2000prof, WIN XP prof
D7EP, MSSQL, ABSDB
BeitragVerfasst: Fr 19.05.06 20:27 
Moin :)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
function CopyFiles( sQuellPfad, sZielPfad:string): boolean;
var
  fos : TSHFILEOPSTRUCT;
begin
    sQuellPfad := sQuellPfad + #0#0;
    sZielPfad := sZielPfad + #0#0;
    {*--FALSCH!!---------------------------------------------------
    FillChar(
SHFILEOPSTRUCT,SizeOf(fos), #0);
    ---------------------------------------------------------------*}

//--RICHTIG:
    FillChar(fos,SizeOf(fos), #0);    
    fos.wnd := Application.Handle;
    fos.wFunc := FO_COPY;
    fos.pFrom := PAnsiChar(sQuellPfad);
    fos.pTo := PAnsiChar(sZielPfad);
    fos.fFlags := FOF_FILESONLY;
    Result := (SHFileOperation(fos) = 0);
end;

:autsch: :autsch: mein Fehler :oops:

Ich hatte meine Funktion auf Deine angepasst, sprich das SHFILEOPSTRUCT durch fos ersetzt, allerdings wohl nicht ganz durchgängig :(
Also mit der geänderten Zeile dürfte die Funktion jetzt problemslos arbeiten..
Dein Funktionsaufruf sieht auf jeden ganz brauchbar aus :)
masteroffinalfantasy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

Win XP
Delphi 2005 Architect
BeitragVerfasst: Sa 20.05.06 12:06 
Hmm also ich habs eingebaut und versuche nun die Dateien zu kopieren. Die Dateinamen lese ich aus einer Datei aus. Insgesamt sieht es dann folgendermaßen aus:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
var d:Textfile;
    spielernamena:Array[1..99of string;
[...]
 
assignfile(d,'mannschaft.txt');
reset(d);
i:=0;
while not eof(d)
do begin
i:=i+1;
readln(d,spielernamena[i]);
end;
closefile(d);
i:=0;
while spielernamena[i]<>'' do begin
showmessage('Spielerdaten\'+inttostr(max)+'\'+Quotedstr(spielernamena[i]+'.txt'))   ;
if CopyFiles('Spielerdaten\'+inttostr(max)+'\'+Quotedstr(spielernamena[i]+'.txt'),'Spielerdaten\'+inttostr(max+1)) then
 begin
 i:=i+1;
 end;
 end;
[...]


Nur Leider kommt anstatt der Dateinamen nur Datenmüll. Die Namen werden richtig in das Array gespeichert.
masteroffinalfantasy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

Win XP
Delphi 2005 Architect
BeitragVerfasst: So 21.05.06 11:50 
hmm ich will ja nicht nerven, aber hat denn keiner eine Idee?
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Mo 22.05.06 08:43 
o.k. nun wissen wir wie die Funktion von außen angesprochen wird. Magst du mal mit dem Debugger schauen, was du dieser konkret für Parameter übergibst?
masteroffinalfantasy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

Win XP
Delphi 2005 Architect
BeitragVerfasst: Mo 22.05.06 09:24 
ok das Problem ist geklärt! Ich hab das Array lokal deklariert....
masteroffinalfantasy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

Win XP
Delphi 2005 Architect
BeitragVerfasst: Mo 22.05.06 10:28 
Jetzt bleibt nur das alte Problem... die Funktion lässt keine Dateilängen mit mehr als 12 Zeichen zu...
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Mo 22.05.06 11:40 
Ich benutze die auch und habe keine Probleme damit.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
function CopyFileEx(const ASource, ADest: String;
 ARenameCheck: boolean = false): boolean;
var
  sh: TSHFileOpStruct;
begin
  sh.Wnd := Application.Handle;
  sh.wFunc := FO_COPY;
  // String muss mit #0#0 Terminiert werden, um das Listenende zu setzen
  sh.pFrom := PChar(ASource + #0);
  sh.pTo := PChar(ADest + #0);
  sh.fFlags := fof_MultiDestFiles or FOF_NOCONFIRMATION or FOF_NOCONFIRMMKDIR;
  if ARenameCheck then
    sh.fFlags := sh.fFlags or fof_RenameOnCollision;
  Result:=ShFileOperation(sh)=0;
end;
masteroffinalfantasy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

Win XP
Delphi 2005 Architect
BeitragVerfasst: Mo 22.05.06 16:07 
hmm auch wenn ich die Funktion benutze speichert er nur die 12 Zeichen ab. Aber wenn es bei dir geht, wieso geht es bei mir nicht O_o
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Mo 22.05.06 18:29 
Ich tippe mal auf die Flags, denn die Parameter werden ja normal lang sein oder?
masteroffinalfantasy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

Win XP
Delphi 2005 Architect
BeitragVerfasst: Mo 22.05.06 22:17 
ja die parameter sind normal lang. wie muss ich die flags denn setzen?