home *** CD-ROM | disk | FTP | other *** search
- Path: news.central.ntua.gr!not-for-mail
- From: hnick@central.ntua.gr (Nick C. Fotis)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: File sizes
- Date: 24 Feb 1996 11:32:57 GMT
- Organization: National Technical University of Athens, Greece
- Message-ID: <4gmt19$b0h@zeus.central.ntua.gr>
- References: <4gd9pu$cpr@mn5.swip.net> <503.6628T113T115@norconnect.no>
- NNTP-Posting-Host: gate2-zeus.central.ntua.gr
- X-Newsreader: NN version 6.5.0 #1 (NOV)
-
- Ok, here something I've made in C with the hope that it someone would find
- it useful.
-
- ------------------------------Cut here ---------------------------------------
- #include <exec/types.h>
- #include <dos/dos.h>
-
- #include <proto/dos.h>
-
- #include <pragmas/dos_pragmas.h>
-
-
- LONG FileSize(char *file)
- {
- BPTR lock;
- struct FileInfoBlock *fib;
- LONG size=-1;
-
- if (lock=Lock(file,ACCESS_READ)) {
- if (fib=(struct FileInfoBlock *) AllocDosObject(DOS_FIB,NULL)) {
- if (Examine(lock,fib)) {
- if (fib->fib_DirEntryType<0)
- size=fib->fib_Size;
- }
- FreeDosObject(DOS_FIB,fib);
- }
- UnLock(lock);
- }
- return size;
- }
- ----------------------------------Cut here -----------------------------------
-
- You pass the name of the file to this function and it returns you the filesize
- in a long.
- Note that in _any_ error (say file not exists, no memory left etc.) the returned
- size is -1.
- Also note the the above limits the size the function can return to about
- two gigabytes (instead of four gigabytes that a ULONG could hold)
- Dunno if DOS places such a limit on its own...
- Cheers,
- Alex Argiropoulos
- --
-
-
-