Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Drag & Drop: Unterscheiden ob Datei oder Ordner (https://www.delphipraxis.net/163325-drag-drop-unterscheiden-ob-datei-oder-ordner.html)

Helmi 24. Sep 2011 17:12

Drag & Drop: Unterscheiden ob Datei oder Ordner
 
Hallo,

ich nutze diesen Code um Dateien z. B. aus dem Explorer per Drag & Drop in ein Edit zu ziehen.

Hab ich die Möglichkeit dabei festzustellen, ob es sich dabei um eine Datei oder um einen Ordner handelt?
Und falls ja, wie?

[Edit]
Ich habs jetzt mal mit DirectoryExists und FileExists getestet - das scheint gut zu funktionieren.
Vielleicht gibts aber noch eine andere Möglichkeit

himitsu 24. Sep 2011 17:37

AW: Drag & Drop: Unterscheiden ob Datei oder Ordner
 
Ich frag einfach die Attribute ab :angle2:


MSDN-Library durchsuchenGetFileAttributes + INVALID_FILE_ATTRIBUTES und FILE_ATTRIBUTE_DIRECTORY

Helmi 24. Sep 2011 17:50

AW: Drag & Drop: Unterscheiden ob Datei oder Ordner
 
Danke für die Antwort.

Ich habs jetzt so gelöst:

Delphi-Quellcode:
FileAttributes := GetFileAttributes(PChar(@pDroppedFilename));

is_File := (FileAttributes <> FILE_ATTRIBUTE_DIRECTORY) and (FileAttributes <> $FFFFFFFF);
is_Dir := FileAttributes = FILE_ATTRIBUTE_DIRECTORY;

himitsu 24. Sep 2011 21:04

AW: Drag & Drop: Unterscheiden ob Datei oder Ordner
 
Nur das mit dem FILE_ATTRIBUTE_DIRECTORY-Bit mußt'e noch reparieren. :angle:

Delphi-Quellcode:
FileAttributes = FILE_ATTRIBUTE_DIRECTORY
liefert ja nur True, wenn sonst keine anderen Attribute gesetzt sind
und is_File würde auch True sagen, wenn die Datei/Verzeichnis nicht existiert oder wenn das "Verzeichnis" noch weitere Attribute besitzt. :wink:

Delphi-Quellcode:
is_File := (FileAttributes and FILE_ATTRIBUTE_DIRECTORY = 0) and (FileAttributes <> $FFFFFFFF);
is_Dir := (FileAttributes and FILE_ATTRIBUTE_DIRECTORY <> 0) and (FileAttributes <> $FFFFFFFF);

// gekürzt, da FILE_ATTRIBUTE_DIRECTORY in INVALID_FILE_ATTRIBUTES enthalten ist
is_File := FileAttributes and FILE_ATTRIBUTE_DIRECTORY = 0;
is_Dir := (FileAttributes and FILE_ATTRIBUTE_DIRECTORY <> 0) and (FileAttributes <> $FFFFFFFF);

Helmi 25. Sep 2011 07:58

AW: Drag & Drop: Unterscheiden ob Datei oder Ordner
 
Zitat:

Zitat von himitsu (Beitrag 1126480)
Nur das mit dem FILE_ATTRIBUTE_DIRECTORY-Bit mußt'e noch reparieren. :angle:

Delphi-Quellcode:
FileAttributes = FILE_ATTRIBUTE_DIRECTORY
liefert ja nur True, wenn sonst keine anderen Attribute gesetzt sind
und is_File würde auch True sagen, wenn die Datei/Verzeichnis nicht existiert oder wenn das "Verzeichnis" noch weitere Attribute besitzt. :wink:

Delphi-Quellcode:
is_File := (FileAttributes and FILE_ATTRIBUTE_DIRECTORY = 0) and (FileAttributes <> $FFFFFFFF);
is_Dir := (FileAttributes and FILE_ATTRIBUTE_DIRECTORY <> 0) and (FileAttributes <> $FFFFFFFF);

// gekürzt, da FILE_ATTRIBUTE_DIRECTORY in INVALID_FILE_ATTRIBUTES enthalten ist
is_File := FileAttributes and FILE_ATTRIBUTE_DIRECTORY = 0;
is_Dir := (FileAttributes and FILE_ATTRIBUTE_DIRECTORY <> 0) and (FileAttributes <> $FFFFFFFF);

Wo du recht hast, hast du recht! (leider :mrgreen:)


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:48 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz