Autor Beitrag
LonghornUser
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 796



BeitragVerfasst: So 22.04.07 10:10 
Hallo,

ist es irgendwie möglich herauszufinden, ob ein Pfad zu einer Datei oder zu einem Ordner führt ?

Danke schonmal.

Ciao LHUser
Andreas L.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1703
Erhaltene Danke: 25

Windows Vista / Windows 10
Delphi 2009 Pro (JVCL, DragDrop, rmKlever, ICS, EmbeddedWB, DEC, Indy)
BeitragVerfasst: So 22.04.07 10:14 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
if DirectoryExists('DeinPfad'then
 //ist ein ordner
else
 // ist kein ordner


In C++ gibts ja IsFile. Ob man das irgendwie in Delphi importieren kann. Aber ich denke das obengenannte sollte funktionieren.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 22.04.07 11:55 
Könnte man so prüfen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
Function IsFile(Filename: String): Boolean;
Begin
    Result := FileExists(Filename) and not FileExists(Filename + '\.');
end;


Nutzt ein wenig Dateisystem-Logik von Windows aus: Die Datei . existiert nur für Verzeichnisse, nicht jedoch für Dateien ;-)

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: So 22.04.07 12:06 
Oder so (FileExists auseinandergenommen):

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var
  DirEx   : Cardinal;
begin
  DirEx:=GetFileAttributesA(PAnsiChar(Root));
  if DirEx<>DWord(-1then
  begin
    if FILE_ATTRIBUTE_DIRECTORY and DirEx=FILE_ATTRIBUTE_DIRECTORY then IstOrdner else IstDatei;
  end;
end;


Was DirEx noch alles beinhaltet siehst du hier
LonghornUser Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 796



BeitragVerfasst: So 22.04.07 12:29 
Erstmal danke für eure Antworten.

@ Andreas L.:
Wenn aber ein Ordner eingegeben wurde, der nicht existiert habe ich ein falsches Ergebnis.
@ BenBE:
Da sagt er bei mir immer Ordner
@ Heiko:
Das könnte klappen, aber ich bekomme die Fehlermeldung
ausblenden Quelltext
1:
[Fehler] Unit10.pas(67): Undefinierter Bezeichner: 'Root'					
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 22.04.07 12:33 
user profile iconLonghornUser hat folgendes geschrieben:
Erstmal danke für eure Antworten.

@ Andreas L.:
Wenn aber ein Ordner eingegeben wurde, der nicht existiert habe ich ein falsches Ergebnis.
@ BenBE:
Da sagt er bei mir immer Ordner

Dann halt so ;-)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
Function IsFile(Filename: String): Boolean;
Begin
    Result := FileExists(Filename) and not DirectoryExists(Filename);
end;

user profile iconLonghornUser hat folgendes geschrieben:
@ Heiko:
Das könnte klappen, aber ich bekomme die Fehlermeldung
ausblenden Quelltext
1:
[Fehler] Unit10.pas(67): Undefinierter Bezeichner: 'Root'					

Root ist das zu prüfende Verzeichnis\Datei.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
LonghornUser Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 796



BeitragVerfasst: So 22.04.07 12:38 
@BenBE: Ahh, jetzt klappt alles. Danke !!! (Es geht mit Heikos und deiner Variante ;) )