• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

File Details.

Hi,

I am running gcc under solaris, i need to know the details of a given file such as its size,  date on which the file was last updated/edited etc. Is there any inbuilt function or other.  responses very much appreciated.

-gsbabu
0
gsbabu
Asked:
gsbabu
  • 3
  • 3
1 Solution
 
nietodCommented:
Unix has a file called fstat() or stat() or something like that.  If linux has it it should provide the info you want.
0
 
MarthiCommented:
Yes. The function is fstat() or stat().
Here's a man page snippet

NAME
       stat, fstat, lstat - get file status

SYNOPSIS
       #include <sys/stat.h>
       #include <unistd.h>

       int stat(const char *file_name, struct stat *buf);
       int fstat(int filedes, struct stat *buf);
       int lstat(const char *file_name, struct stat *buf);

DESCRIPTION
       These  functions  return  information  about the specified
       file.  You do not need any access rights to  the  file  to
       get  this  information  but  you need search rights to all
       directories named in the path leading to the file.


0
 
gsbabuAuthor Commented:
i have used stat(), but i don't know the exact syntax of the second parameter, i get error for

stat("/home/cachet/longfilename",time_t->st_ctime)

please guide me where i am wrong.

-gsbabu
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
nietodCommented:
Its a pointer to a structure of type stat.  The function will fill in this structure with the information about the file.
0
 
gsbabuAuthor Commented:
Could you correct the second parameter as to how pass a pointer.

-gsbabu
0
 
nietodCommented:
struct stat Stat;

stat("/home/cachet/longfilename",&Stat)

then use Stat.????
0
 
gsbabuAuthor Commented:
Thanks for your suggestions/comments.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now