home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / acl-lib.zip / ACLFindFunctions.pas < prev    next >
Pascal/Delphi Source File  |  2000-05-13  |  2KB  |  93 lines

  1. unit ACLFindFunctions;
  2. // Replacements/wrappers for file find functions
  3. // The main problem is that I have had problems
  4. // with the Delphi functions.
  5. interface
  6.  
  7. uses
  8.   SysUtils;
  9.  
  10. type
  11.   TSearchData = SysUtils.TSearchRec;
  12.  
  13. function MyFindFirst( const Path: string;
  14.                       var F: TSearchData ): integer;
  15. function MyFindNext( var F: TSearchData ): Integer;
  16. procedure MyFindClose(var F: TSearchData);
  17.  
  18. implementation
  19.  
  20. {$ifdef win32}
  21. uses
  22.   Windows;
  23.   
  24. procedure TranslateFindData( var F: TSearchData );
  25. var
  26.   LocalFileTime: TFileTime;
  27. begin
  28.   with F do
  29.   begin
  30.     FileTimeToLocalFileTime( FindData.ftLastWriteTime,
  31.                              LocalFileTime );
  32.     FileTimeToDosDateTime( LocalFileTime,
  33.                            LongRec(Time).Hi,
  34.                            LongRec(Time).Lo );
  35.     Size := FindData.nFileSizeLow;
  36.     Attr := FindData.dwFileAttributes;
  37.     Name := FindData.cFileName;
  38.   end;
  39. end;
  40.  
  41. function MyFindFirst( const Path: string;
  42.                       var F: TSearchData ): integer;
  43. const
  44.   faSpecial = faHidden or faSysFile or faVolumeID or faDirectory;
  45. begin
  46.   F.FindHandle := FindFirstFile( PChar( Path ), F.FindData );
  47.  
  48.   if F.FindHandle = INVALID_HANDLE_VALUE then
  49.     Result:= ERROR_NO_MORE_FILES
  50.   else
  51.   begin
  52.     TranslateFindData( F );
  53.     Result:= 0;
  54.   end;
  55. end;
  56.  
  57. function MyFindNext( var F: TSearchData ): Integer;
  58. begin
  59.   if FindNextFile( F.FindHandle, F.FindData ) then
  60.   begin
  61.     Result:= 0;
  62.     TranslateFindData( F );
  63.   end
  64.   else
  65.     Result:= 1;
  66. end;
  67.  
  68. procedure MyFindClose(var F: TSearchData);
  69. begin
  70.   Windows.FindClose( F.FindHandle );
  71. end;
  72. {$else}
  73. // OS/2 versions: just pass thru to Sibyl versions.
  74. function MyFindFirst( const Path: string;
  75.                       var F: TSearchData ): integer;
  76. begin
  77.   Result:= SysUtils.FIndFirst( Path, faAnyFile, F );
  78. end;
  79.  
  80. function MyFindNext( var F: TSearchData ): Integer;
  81. begin
  82.   Result:= SysUtils.FindNext( F );
  83. end;
  84.  
  85. procedure MyFindClose(var F: TSearchData);
  86. begin
  87.   SysUtils.FindClose( F );
  88. end;
  89. {$endif}
  90.  
  91.  
  92. end.
  93.