Welcome, Guest. Please login or register.

Author Topic: OS call to get file size  (Read 2724 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline gazspTopic starter

  • Jr. Member
  • **
  • Join Date: Sep 2004
  • Posts: 71
    • Show only replies by gazsp
    • http://realitydesign.asn.org.uk
OS call to get file size
« on: October 29, 2005, 10:36:41 PM »
Me again :-)

Any ideas anybody? Can I get it from using Lock()?
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: OS call to get file size
« Reply #1 on: October 29, 2005, 10:45:27 PM »
dos.library/Examine

See dos/dos.h 'struct FileInfoBlock', fib_Size holds the size.
 

Offline gazspTopic starter

  • Jr. Member
  • **
  • Join Date: Sep 2004
  • Posts: 71
    • Show only replies by gazsp
    • http://realitydesign.asn.org.uk
Re: OS call to get file size
« Reply #2 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 :-)
 

Offline DariusB

  • Newbie
  • *
  • Join Date: Jun 2005
  • Posts: 8
    • Show only replies by DariusB
    • http://people.freenet.de/dariusb/
Re: OS call to get file size
« Reply #3 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
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: OS call to get file size
« Reply #4 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.
 

Offline Castellen

Re: OS call to get file size
« Reply #5 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!
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: OS call to get file size
« Reply #6 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;);
  }

 

Offline Castellen

Re: OS call to get file size
« Reply #7 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.