Recent

Author Topic: skip large files when processing  (Read 1338 times)

BobDog

  • Sr. Member
  • ****
  • Posts: 394
Re: skip large files when processing
« Reply #15 on: October 19, 2022, 09:17:18 pm »

A Windows method
fast filesize, and some optional file information from msvcrt.dll.
Code: Pascal  [Select][+][-]
  1.  
  2. uses
  3. sysutils;
  4.  
  5.  
  6. function wstat (w:widestring;st:pointer):int32; cdecl external 'msvcrt.dll' name '_wstat';
  7. function ctime (p:pointer):pchar;cdecl external 'msvcrt.dll' name 'ctime';
  8.  
  9. type stats =record
  10.  st_dev:uint32;
  11.  st_ino:word;
  12.  st_mode:word;
  13.  st_nlink :int16;
  14.  st_uid :int16;
  15.  st_gid :int16;
  16.  st_rdev:uint32;
  17.  st_size :int32;
  18.  st_atime :int64;
  19.  st_mtime :int64;
  20.  st_ctime :int64;
  21. end;
  22.  
  23.  
  24.  
  25. function filesize(filename:widestring):int32;
  26. var
  27. filestat:stats;
  28. v:int32;
  29. begin
  30. v:=wstat(filename,@filestat);
  31. exit(filestat.st_size);
  32. end;
  33.  
  34. procedure fileinfo(filename:widestring);
  35. var
  36. filestat:stats;
  37. v:int64;
  38. begin
  39. v:=wstat(filename,@filestat);
  40. writeln ('File create time ',ctime(@filestat.st_ctime));
  41. writeln ('File access time ',ctime(@filestat.st_atime));
  42. writeln ('File modify time ',ctime(@filestat.st_mtime));
  43. end;
  44.  
  45.  
  46.  
  47.   var filepath:widestring='absolute.exe';
  48.   var t:int64;
  49.  
  50. begin
  51.  
  52. t:=gettickcount64;
  53. writeln('file size ',filesize(filepath),#10);
  54. writeln('Time taken to get size ',gettickcount64-t,#10);
  55. fileinfo(filepath);
  56.  
  57. writeln('Press return to exit');
  58. readln;
  59.  
  60. end.
  61.  
  62.  

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2068
  • Fifty shades of code.
    • Delphi & FreePascal
Re: skip large files when processing
« Reply #16 on: October 19, 2022, 09:28:46 pm »
For Windows I would use "GetFileAttributesEx" Windows API.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

ASerge

  • Hero Member
  • *****
  • Posts: 2242
Re: skip large files when processing
« Reply #17 on: October 19, 2022, 09:37:14 pm »
All the best ideas from the thread in a ZIP file
There is no need to repeat the FileSize implementation. As already wrote @pawel, you can use FileUtil.FileSize.
In general, I would also recommend using an additional check via FileExists to exclude names like *.txt, which the current implementation allows.

 

TinyPortal © 2005-2018