Entwickler-Ecke

Dateizugriff - Unicode fähige FileExists Funktion?


jerilynn - Di 19.06.07 18:59
Titel: Unicode fähige FileExists Funktion?
Hallo,

ich wollte fragen ob jemand eine Unicode fähige FileExists Funktion kennt die auch mit WideStrings (also Unicode Strings) zurecht kommt? Habe bestimmt schon das halbe Internet abgegrast leider ohne Erfolg.


Greez
Lynn


Ghostwalker - Di 19.06.07 21:30

Spontan würd ich sagen dürfte bei der JCL was dabei sein:

http://www.delphi-jedi.org/ ->JCL [http://www.delphi-jedi.org/]


Delete - Di 19.06.07 22:49


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
function FileExistsW(const FileName: WideString): Boolean;
var
  Attr: Cardinal;
begin
  Attr := GetFileAttributesW(PWideChar(Filename));
  Result := (Attr <> $FFFFFFFFand (Attr and FILE_ATTRIBUTE_DIRECTORY = 0);
end;


Reinhard Kern - Mi 20.06.07 07:29
Titel: Re: Unicode fähige FileExists Funktion?
user profile iconjerilynn hat folgendes geschrieben:
Hallo,

ich wollte fragen ob jemand eine Unicode fähige FileExists Funktion kennt die auch mit WideStrings (also Unicode Strings) zurecht kommt? Habe bestimmt schon das halbe Internet abgegrast leider ohne Erfolg.


Greez
Lynn


Hallo,

die "offizielle" Methode ist wohl FindFirstFileW. Kommentar bei MS:

In the ANSI version of this function, the name is limited to MAX_PATH CHARs. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File.

Wenn das Ergebnis ein ungültiges Handle ist, existiert die Datei nicht oder ist nicht zugreifbar, was für die Software auf das Gleiche herauskommt.

Gruss Reinhard


jerilynn - Mi 20.06.07 15:21

Dankeschön:) Jetzt funktionierts :)