瀏覽代碼

* fixes for FileExists and DirectoryExists

git-svn-id: trunk@18885 -
Tomas Hajny 14 年之前
父節點
當前提交
55685d11b2
共有 1 個文件被更改,包括 21 次插入20 次删除
  1. 21 20
      rtl/watcom/sysutils.pp

+ 21 - 20
rtl/watcom/sysutils.pp

@@ -289,33 +289,34 @@ end;
 
 
 Function FileExists (Const FileName : String) : Boolean;
-Var
-  Sr : Searchrec;
 begin
-  DOS.FindFirst(FileName,$3f,sr);
-  if DosError = 0 then
-   begin
-     { No volumeid,directory }
-     Result:=(sr.attr and $18)=0;
-     Dos.FindClose(sr);
-   end
+  if FileName = '' then
+   Result := false
   else
-   Result:=false;
+   Result := FileGetAttr (ExpandFileName (FileName)) and
+                                               (faDirectory or faVolumeID) = 0;
+(* Neither VolumeIDs nor directories are files. *)
 end;
 
 
-Function DirectoryExists (Const Directory : String) : Boolean;
-Var
-  Sr : Searchrec;
+function DirectoryExists (const Directory: string): boolean;
+var
+  L: longint;
 begin
-  DOS.FindFirst(Directory,$3f,sr);
-  if DosError = 0 then
-   begin
-     Result:=(sr.attr and $10)=$10;
-     Dos.FindClose(sr);
-   end
+  if Directory = '' then
+   Result := false
   else
-   Result:=false;
+   begin
+    if (Directory [Length (Directory)] in AllowDirectorySeparators) and
+                                              (Length (Directory) > 1) and
+(* Do not remove '\' after ':' (root directory of a drive) 
+   or in '\\' (invalid path, possibly broken UNC path). *)
+      not (Directory [Length (Directory) - 1] in AllowDriveSeparators + AllowDirectorySeparators) then
+     L := FileGetAttr (ExpandFileName (Copy (Directory, 1, Length (Directory) - 1)))
+    else
+     L := FileGetAttr (ExpandFileName (Directory));
+    Result := (L > 0) and (L and faDirectory = faDirectory);
+   end;
 end;