Autor Beitrag
Wolle92
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Mi 25.07.07 09:24 
hallo,

wie kann ich bei einer Liste der Dateien, die sich in einem Verzeichnis befinden, das Symbol des Dateityps und den Typ mit anzeigen lassen?
Da ich auch noch Größe und Typ anzeigen lassen will, benutze ich eine ListBox...
Also:
Wie kann ich den Dateityp einer Datei ermitteln und wie kann ich das Symbol dazu anzeigen lassen?

Edit: Meine ein Listview
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mi 25.07.07 10:23 
Hallo,

dort hatte ich mal ein Beispiel geschrieben, aus dem man das Grundsätzliche entnehmen kann:
Icons von Dateiendungen auslesen
Das bezieht sich zwar speziell auf Dateiendungen, aber der Code verdeutlicht gut die Auswertung/Ausgabe in einem ListView.

Ein Stichwort für eine weitere Suche zu dem Thema: TSHFileInfo
Der Tateityp steht im Struktur-Feld: TSHFileInf.szTypeName

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Mi 25.07.07 10:27 
das reicht ja, man kann ja die Dateiendung herausnehmen und bestimmen...
Danke...
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mi 25.07.07 10:59 
Hallo,
user profile iconWolle92 hat folgendes geschrieben:
das reicht ja, man kann ja die Dateiendung herausnehmen und bestimmen...
:autsch:

Wenn Du nachschauen willst ob an Deinem fahrbaren Untersatz das Profil der Reifen noch in Ordnung ist, baust du dann die Räder ab? :wink:

ausblenden Delphi-Quelltext
1:
2:
SHGetFileInfo(PChar(aPfad),0, Info, SizeOf(TSHFileInfo),  
            SHGFI_ICON or SHGFI_SMALLICON or SHGFI_TYPENAME);

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Mi 25.07.07 12:01 
ähmm... und was bedeutet das im einzelnen? einfach nur schrieben, ohne zu wissen was eigentlich, mach ich nicht gerne...
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mi 25.07.07 12:47 
Hallo,

find ich gut :zustimm:
über die Funktion SHGetFileInfo, und alles was damit zusammenhängt, könnte man ein kleines Buch schreiben :wink:

- Cursor in die Funktion im Editor setzen + F1
- in der PSDK
- Microsoft: msdn2.microsoft.com/...ibrary/ms647761.aspx
- etwas über den Tellerrand geschaut: www.aboutvb.de/khw/a...kel/khwassocicon.htm
- und noch das: www.vbapihelpline.de...4?Func=SHGetFileInfo

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Mi 25.07.07 19:42 
Danke, wie baue ich das so ein, dass das Symbol in der gleichen Spalte wie der dateiname angezeigt wird?
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:
procedure TForm1.FindFiles(Path: String);
var sr: TSearchRec;
    r: Integer;
    liNew: TListItem;
begin
  r := FindFirst(Path + '\*.*', faAnyFile, sr);
  while r = 0 do
  begin
    if sr.Name <> '.' then
    begin
      if ((sr.Attr and faDirectory) <> 0then
      begin
        liNew := ListView1.Items.Add;
        liNew.Caption := sr.Name;
        liNew.SubItems.Add('');
        liNew.SubItems.Add('Ordner');
      end
      else
      begin
        liNew := ListView1.Items.Add;
        liNew.Caption := sr.Name;
      end;
    end;
    Application.ProcessMessages;
    r := FindNext(sr);
  end;
  FindClose(sr);
end;
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mi 25.07.07 20:27 
Hallo,

für das Zuweisen des Icons sind die Zeilen aus dem Code den ich im zweiten Beitrag verlinkt habe zuständig:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
//...
var Info: TSHFileInfo;
//...
begin
//...
//Icon ermitteln
  SHGetFileInfo(PChar(aFile), FILE_ATTRIBUTE_NORMAL, Info, SizeOf(TSHFileInfo),  
            SHGFI_ICON or SHGFI_SMALLICON or SHGFI_USEFILEATTRIBUTES);  
//Icon zuweisen
  aItem.ImageIndex := Info.IIcon;
noch etwas die Variablennamen anpassen, fertig

aber denke daran die Funktion zur Initialisierung aus dem Beitrag in Deine Anwendung einzubauen.

Ich sehe gerade das dein FindFiles auch die Ordner einliest. Wenn Du den verlinkten Beitrag mal etwas weiter durchliest findest Du auch dazu etwas.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Do 26.07.07 10:51 
bei mir ist das alles ein "Undeclared Identifier"... brauch man dafür noch eine bestimmte Unit?
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Do 26.07.07 11:36 
Hallo,

die Struktur/ der Record TSHFileInfo ist in der unit ShellApi definiert.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Do 26.07.07 14:47 
was habe ich faslch gemacht?
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:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
procedure TForm1.FindFiles(Path: String);
var sr: TSearchRec;
    r: Integer;
    c_file: TFileStream;
    size_r: Real;
    size_s: String;
    size_fmt_i: Integer;
    size_fmt: String;
    liNew: TListItem;
    Info: TSHFileInfo;
begin
  r := FindFirst(Path + '\*.*', faAnyFile, sr);
  while r = 0 do
  begin
    size_fmt_i := 1;
    if sr.Name <> '.' then
    begin
      if ((sr.Attr and faDirectory) <> 0then
      begin
        liNew := ListView1.Items.Add;
        liNew.Caption := sr.Name;
        liNew.SubItems.Add('');
        liNew.SubItems.Add('Ordner');
      end
      else
      begin
        c_file := TFileStream.Create(Path + '\' + sr.Name, fmOpenRead);
        size_r := StrToFloat(IntToStr(c_file.Size));
        while size_r > 999 do
        begin
          size_r := size_r / 1000;
          Inc(size_fmt_i);
        end;
        case size_fmt_i of
          1: size_fmt := ' B';
          2: size_fmt := ' KB';
          3: size_fmt := ' MB';
          4: size_fmt := ' GB';
        end;
        size_r := size_r * 10;
        size_r := Trunc(size_r);
        size_r := size_r / 10;
        size_s := FloatToStr(size_r) + size_fmt;
        SHGetFileInfo(PChar(path + '\' + sr.Name), FILE_ATTRIBUTE_NORMAL, Info, SizeOf(TSHFileInfo), SHGFI_ICON or SHGFI_SMALLICON or SHGFI_USEFILEATTRIBUTES);

        liNew := ListView1.Items.Add;
        liNew.ImageIndex := Info.IIcon;
        liNew.Caption := sr.Name;
        liNew.SubItems.Add(size_s);
        c_file.Free;
      end;
    end;
    Application.ProcessMessages;
    r := FindNext(sr);
  end;
  FindClose(sr);
end;
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Do 26.07.07 14:52 
erledigt, habs rausgefunden, aber in dem verlinkten beitrag steht ja was wegen den Ordnern, aber das funktioniert bei mir nur bei den Ordnern die auf dem Desktop sind
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Do 26.07.07 16:17 
Hallo,

bei mir funktioniert das bei allen Ordnern.

Was übergibst Du an die Funktion, welches Icon -oder keins- zeigt er bei Fehlfunktion an, wie sieht dein Code aus?
Die Funktion erfordert den kompletten Pfad.

//Edit: Desktop funktioniert, dann liegt es am Pfad.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Do 26.07.07 16:38 
Okay, stimmt... jetzt klappts, nur der ".." hat noch so ein leeres Blatt, wie bei unbekannten Dateien oder Dateien ohne Endung
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Do 26.07.07 17:22 
Hallo,

übergehe sie doch, oder sollen die '..' Verzeichnisse angezeigt werden.

Kannst Dir auch den IconIndex eines normalen Verzeichnisses merken und für diese anwenden.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Do 26.07.07 17:27 
ja, die sollen angezeigt werden, damit man einfach ins übergeordnete Verzeichnis wechseln kann
aber leider wird das immer als erstes angezeigt...

Okay, ich lass den Index jetzt speichern, nur leider gibt es ja ordner, die spezielle Symbole haben... dann hat der ".."-Ordner in C:\Users\Wolle\ das Symbol des Video-Ordners
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Do 26.07.07 17:43 
Hallo,

und was hindert Dich daran vorab den Iconindex von einem Verzeichnis abzufragen bei dem Du sicher bist das es das normale Verzeichnis-Icon hat?

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Do 26.07.07 17:46 
Nichts... okay...
Aber das Programm soll doch auch auf anderen PCs laufen, da weiß ich doch nicht, ob es bei denen das Verzeichnis gibt...
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Do 26.07.07 17:52 
Hallo,

dann hol Dir das von dem übergeordneten Verzeichnis.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Do 26.07.07 17:53 
stimmt, ergibt ja auch irgendwo sinn...