Amiga.org

Operating System Specific Discussions => Amiga OS => Amiga OS -- Development => Topic started by: gazsp on October 29, 2005, 10:36:41 PM

Title: OS call to get file size
Post by: gazsp on October 29, 2005, 10:36:41 PM
Me again :-)

Any ideas anybody? Can I get it from using Lock()?
Title: Re: OS call to get file size
Post by: Piru on October 29, 2005, 10:45:27 PM
dos.library/Examine

See dos/dos.h 'struct FileInfoBlock', fib_Size holds the size.
Title: Re: OS call to get file size
Post by: gazsp on October 30, 2005, 12:09:06 AM
Cool, cheers. I used to know that one but I haven't done any Amiga programming for a while :-)
Title: Re: OS call to get file size
Post by: DariusB on January 28, 2006, 09:30:04 PM
a other method i used a lot is a double call of Seek(), it returns the postition of the last i/o call

Seek(filehd, 0, OFFSET_END);
len = Seek(filehd, 0, OFFSET_BEGINNING);

the 1st seeks to the end of the file so the 2nd call returns the position of the last dos i/o
Title: Re: OS call to get file size
Post by: Piru on January 28, 2006, 09:58:10 PM
@DariusB

I left that method out for a reason: It's ultraslow with ffs and large files. It should be avoided.
Title: Re: OS call to get file size
Post by: Castellen on January 28, 2006, 09:59:31 PM
Or use lstat()


#include

struct stat *stat_info;

lstat("filename", stat_info);

printf("The file is %d bytes in size", stat_info->st_size);


Or something like that anyway.  I think the beers are having an adverse affect on my memory :pint:
Just noticed that original post was October last year.  I hope he's figured it out by now!
Title: Re: OS call to get file size
Post by: Piru on January 28, 2006, 10:10:09 PM
@Castellen
Code: [Select]

#include <sys/stat.h>
#include <stdio.h>

  struct stat stat_info;

  if (lstat(&quot;filename&quot;, &stat_info) != -1)
  {
    printf(&quot;The file is %d bytes in size\n&quot;, stat_info.st_size);
  }
  else
  {
    perror(&quot;lstat&quot;);
  }

Title: Re: OS call to get file size
Post by: Castellen on January 28, 2006, 10:20:57 PM
Yep, makes sense to use it without using structure pointers like that.

Not sure if this is the most efficient way to do the job, but also in the "stat" structure are things like file date, file comments, etc, which can be useful.

It's a good general purpose "give me every information available about a file" type of function.