Online
Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.079 Beiträge
Delphi 12 Athens
|
Dateiname auf Gültigkeit prüfen
29. Jul 2005, 04:32
Zum Beitrag " Dateiname auf Gültigkeit prüfen"
So, und hier ist mal meine Version -.-''
Delphi-Quellcode:
Type TCFNameMode = Set of (
cnmDOSCompatible, // Tests for file modifier characters ("+", ";", "=" ...).
cnm8Point3Names, // Tests for short file names (8.3).
cnmQuoteEnabled); // File name may be included into quotation marks (").
Function CheckFilename(FileName: AnsiString; Mode: TCFNameMode = []; Directory: AnsiString = ''): ByteBool;
Var i: Integer;
Quoted: Boolean;
Buffer: Array[1..MAX_PATH] of AnsiChar;
P: PAnsiChar;
Begin
Result := False;
If FileName = '' Then Exit;
Quoted := (cnmQuoteEnabled in Mode) and (FileName[1] = '"') and (FileName[Length(FileName)] = '"');
If Quoted Then FileName := Copy(FileName, 2, Length(FileName) - 2);
If (FileName[1] = ' ') and (FileName[Length(FileName)] = ' ') Then Exit;
For i := Length(FileName) downto 1 do
If (FileName[i] in [#0..#31, '"', '*', '/', ':', '<', '>', '?', '\', '|']) or
((cnmDOSCompatible in Mode) and (not Quoted) and (FileName[i] in ['+', ';', '=', '[', ']'])) or
(((cnm8Point3Names in Mode) or ((cnmQuoteEnabled in Mode) and not Quoted)) and (FileName[i] = ' ')) Then Exit;
If cnm8Point3Names in Mode Then Begin
i := Pos('.', FileName);
If i = 0 Then i := Length(FileName) + 1;
If (i > 9) or (Length(FileName) - i > 3) or (PosEx('.', FileName, i + 1) > 0) Then Exit;
End;
If Directory <> '' Then Begin
If Directory[Length(Directory)] <> '\' Then Directory := Directory + '\';
FileName := Directory + FileName;
End;
i := GetFullPathNameA(PAnsiChar(FileName), MAX_PATH, @Buffer, P);
If (i <= 0) or (i >= MAX_PATH) Then Exit;
Result := True;
End;
If not CheckFilename(FileName) Then Error...
Neuste Erkenntnis:
Seit Pos einen dritten Parameter hat,
wird PoSex im Delphi viel seltener praktiziert.
|
|
|