Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

File Details.

Posted on 2000-02-28
7
Medium Priority
?
229 Views
Last Modified: 2010-04-02
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
Comment
Question by:gsbabu
  • 3
  • 3
7 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 2566333
Unix has a file called fstat() or stat() or something like that.  If linux has it it should provide the info you want.
0
 

Accepted Solution

by:
Marthi earned 105 total points
ID: 2566336
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
 

Author Comment

by:gsbabu
ID: 2566492
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:nietod
ID: 2566712
Its a pointer to a structure of type stat.  The function will fill in this structure with the information about the file.
0
 

Author Comment

by:gsbabu
ID: 2566758
Could you correct the second parameter as to how pass a pointer.

-gsbabu
0
 
LVL 22

Expert Comment

by:nietod
ID: 2566765
struct stat Stat;

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

then use Stat.????
0
 

Author Comment

by:gsbabu
ID: 2566810
Thanks for your suggestions/comments.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question