Autor Beitrag
Brothy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32



BeitragVerfasst: So 24.09.06 20:47 
hi alle,
ich hab ein Problem. Und zwar will ich musik dateien sortieren.Der Suchalgorithmus funktionier wunderbar, aber der zum kopieren (also der, der sortiert) noch nicht!
Hier mal erklärungen:
files ist eine TStringList
k ist integer
ID3v2Tag ist der Tag der mp3 dateien, also um infos zu holn
path_tmp ist der neue pfad, also wo die dateien hinkopiert werden sollen (sortiert)
und der dazu ausgehende pfad ist path
Ich hoffe ihr habt es verstanden!
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:
23:
24:
25:
26:
27:
28:
29:
procedure TForm1.Sortiere(path : String);
var k : integer;
    path_tmp : String;
    ID3v2Tag : TID3v2Tag;
begin
  if path[length(path)] <> '\' then path := path + '\' ;
  // schauen ob sortierungsordner existieren 0,1,2,A,B,C ...
  for k := ord('0') to ord('9') do if not (DirectoryExists(path +chr(k))) then
    ForceDirectories(path + chr(k));
  for k := ord('A') to ord('Z') do if not (DirectoryExists(path +chr(k))) then
    ForceDirectories(path + chr(k));
  ID3v2Tag := TID3v2Tag.Create;
  for k := 0 to files.Count-1 do    //dateien kopieren
    begin
      showmessage(files[k]);  // es werden die richtigen Pfade angezeigt
      ID3v2Tag.ReadFromFile(files[k]);
      if (ID3v2Tag.Artist <> '') then path_tmp := path + UpperCase(ID3v2Tag.Artist[1]) + '\' else path_tmp := path + 'Unknown\';
      if FileExists(path_tmp + ExtractFilename(files[k])) = false then
        begin
          if not (DirectoryExists(pChar(path_tmp + ID3v2Tag.Artist))) then ForceDirectories(pChar(path_tmp + ID3v2Tag.Artist));
          CopyFile(PChar(files[k]),PChar(path_tmp + ID3v2Tag.Artist),true);
        end;
      if Checkbox1.Checked then   //ursprungsdatei löschen
        begin          //muss noch gemacht werden, aber erst muss fehler behoben werden!

        end;
    end;
  ID3v2Tag.destroy;
end;

Irgendwo isn fehler drin, weil er die dateien net kopiert!
Ich find den Fehler nur grad net.

Mfg Brothy
Postskriptum:
Ich hoffe ihr könnt mir helfen


Moderiert von user profile iconChristian S.: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am Mo 25.09.2006 um 00:02
WASEO
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 56

Win98, Win2000, WinXP
D6 Prof, D7 Prof
BeitragVerfasst: So 24.09.06 22:30 
ausblenden Delphi-Quelltext
1:
if FileExists(path_tmp + ExtractFilename(files[k])) = false then ...					


So wie ich es verstehe, soll das Programm die Datei also kopieren, wenn sie nicht existiert (FileExists = false). Büschn seltsam. Sollte es nicht eher "if FileExists(...) = true" heißen?

_________________
Erstaunlich sind nicht die Dinge, die wir nicht kennen, sondern die wir kennen und die nicht so sind.
Brothy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32



BeitragVerfasst: Mo 25.09.06 15:00 
nein denke nicht, an der Stelle sollte es stimmen, da wird nur überprüft ob an der neuen Stelle (also pfad) die Datei schon existiert, wenn nicht dann sollte das programm Sie kopieren!
Ich habs über die Funktion CopyFileEx(PChar(files[k]),PChar(path_tmp + ID3v2Tag.Artist),true);
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
function TForm1.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_Silent or fof_MultiDestFiles;
  if ARenameCheck then
    sh.fFlags := sh.fFlags or fof_RenameOnCollision;
  Result:=ShFileOperation(sh)=0;
end;

auch schon probiert, aber da kommt eine Fehlermeldung, dass der Pfad nicht korrekt sei, also glaube ich dass was mit den Parametern bzw mit dem Pfad net stimmt. Ich find den Fehler aber net :-(
Mfg Brothy
PS: Sorry,dass ichs ins falsche forum gepostet hab ;-)
Und, dass der Code net so schön is ;)
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: Mo 25.09.06 16:22 
Wenn du vermutest, dass der Pfad falsch "ausgegeben" wird, dnn zeig ihn dir doch einfach mal per ShowMessage an. Dann siehst du gleich, ob der Pfad bzw. die Parameter stimmen oder ned. So mach ich das immer...
Brothy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32



BeitragVerfasst: Mo 25.09.06 19:03 
jo danke erstma, aufs einfachste komm ich wieder net ^^
oben im code is schon eine drinne zum schaun ^^
mfg brothy
Brothy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32



BeitragVerfasst: Mo 25.09.06 19:09 
hehe danke also ich schreib noch schnell den fehler!
ich hab beim kopieren den pfad angegeben aber nicht den ganzen, also mit dateiname:
statt
ausblenden Delphi-Quelltext
1:
CopyFile(PChar(files[k]),PChar(path_tmp + ID3v2Tag.Artist),true);					

sollte es heissen:
ausblenden Delphi-Quelltext
1:
CopyFile(PChar(files[k]),PChar(path_tmp + ExtractFilename(files[k])),true);					


Mfg Brothy