Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9121583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:53:44+00:00 2026-06-17T05:53:44+00:00

I have this recursive function to search the tree structure of files. And I

  • 0

I have this recursive function to search the tree structure of files. And I need to find out the parameters of each file (type, owner, group, permissions, creation date, last modification date, ..) How to do it?

void search(const char * path)
{
  char newpath[PATH_SIZE + 1];

  DIR * dp;
  struct dirent * ep;

  dp = opendir(path);
  if (dp == NULL)
    return;

  while ((ep = readdir(dp)) != NULL)
  {
    if (strcmp(".",  ep->d_name) == 0 ||
        strcmp("..", ep->d_name) == 0)
    {
      continue;
    }

    printf("%s/%s\n", path, ep->d_name);


    if ((ep->d_type & DT_DIR) == DT_DIR)
    {
      if (strlen(path) + strlen(ep->d_name) + 1 <= PATH_SIZE)
      {
        sprintf(newpath, "%s/%s", path, ep->d_name);
        search(newpath);
      }
    }
  }

  closedir(dp);

  return;
}

I only know the type of file (ep-> d_type);

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:53:45+00:00Added an answer on June 17, 2026 at 5:53 am

    By the stat() function:

    Manual: man 2 stat

    Prototype:

       int stat(const char *path, struct stat *buf);
       int fstat(int fd, struct stat *buf);
       int lstat(const char *path, struct stat *buf);
    

    where the stat structure is defined as:

       struct stat {
           dev_t     st_dev;     /* ID of device containing file */
           ino_t     st_ino;     /* inode number */
           mode_t    st_mode;    /* protection */
           nlink_t   st_nlink;   /* number of hard links */
           uid_t     st_uid;     /* user ID of owner */
           gid_t     st_gid;     /* group ID of owner */
           dev_t     st_rdev;    /* device ID (if special file) */
           off_t     st_size;    /* total size, in bytes */
           blksize_t st_blksize; /* blocksize for file system I/O */
           blkcnt_t  st_blocks;  /* number of 512B blocks allocated */
           time_t    st_atime;   /* time of last access */
           time_t    st_mtime;   /* time of last modification */
           time_t    st_ctime;   /* time of last status change */
       };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey people i have this structure for the search tree class State { //CLASS
I have a recursive data type like this: template<typename T> struct SomeType { std::map<T,
Imagine I have a recursive algebraic data type like this (Haskell syntax): data Expr
I have a function that lets me write the file-path of files to a
I have written a simple depth-first search in Scala with a recursive function like
I have a recursive function to find the starting index of a substring within
I have the following recursive function that is used to search down a hierarchical
I have this recursive method which deletes empty folders: private void DeleteEmpty(DirectoryInfo directory) {
i have this recursive code <ul> <% sql=SELECT * FROM cats ORDER BY orderid
I have this recursive method: public Hund getMor(int id) { Hund barn = getHund(id);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.