• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • 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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

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