home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 3776 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  56 lines

  1. Path: news.central.ntua.gr!not-for-mail
  2. From: hnick@central.ntua.gr (Nick C. Fotis)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: File sizes
  5. Date: 24 Feb 1996 11:32:57 GMT
  6. Organization: National Technical University of Athens, Greece
  7. Message-ID: <4gmt19$b0h@zeus.central.ntua.gr>
  8. References: <4gd9pu$cpr@mn5.swip.net> <503.6628T113T115@norconnect.no>
  9. NNTP-Posting-Host: gate2-zeus.central.ntua.gr
  10. X-Newsreader: NN version 6.5.0 #1 (NOV)
  11.  
  12. Ok, here something I've made in C with the hope that it someone would find
  13. it useful.
  14.  
  15. ------------------------------Cut here ---------------------------------------
  16. #include <exec/types.h>
  17. #include <dos/dos.h>
  18.  
  19. #include <proto/dos.h>
  20.  
  21. #include <pragmas/dos_pragmas.h>
  22.  
  23.  
  24. LONG    FileSize(char *file)
  25. {
  26.   BPTR    lock;
  27.   struct FileInfoBlock *fib;
  28.   LONG    size=-1;
  29.   
  30.   if (lock=Lock(file,ACCESS_READ)) {
  31.     if (fib=(struct FileInfoBlock *) AllocDosObject(DOS_FIB,NULL)) {
  32.       if (Examine(lock,fib)) {
  33.     if (fib->fib_DirEntryType<0)
  34.       size=fib->fib_Size;
  35.       }
  36.       FreeDosObject(DOS_FIB,fib);
  37.     }
  38.     UnLock(lock);
  39.   }
  40.   return size;
  41. }
  42. ----------------------------------Cut here -----------------------------------
  43.  
  44. You pass the name of the file to this function and it returns you the filesize
  45. in a long.
  46. Note that in _any_ error (say file not exists, no memory left etc.) the returned
  47. size is -1.
  48. Also note the the above limits the size the function can return to about
  49. two gigabytes (instead of four gigabytes that a ULONG could hold) 
  50. Dunno if DOS places such a limit on its own...
  51. Cheers,
  52.   Alex Argiropoulos 
  53. --
  54.  
  55.  
  56.