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

  • Home
  • SEARCH
  • 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 739791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:26:28+00:00 2026-05-14T08:26:28+00:00

I am reading the content of the current library with readdir , but I

  • 0

I am reading the content of the current library with readdir, but I would like to treat only files and not directories. How do I know that I am pointing to a directory and not to a file?

  • 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-05-14T08:26:28+00:00Added an answer on May 14, 2026 at 8:26 am

    You can use lstat, and the S_ISDIR macro.

    E.g. without error-checking:

    struct stat buffer;
    int status;
    char path[PATH_MAX];
    DIR *dir = opendir(dir_name);
    ... 
    struct dirent *de = readdir(dir);
    sprintf(path, "%s/%s", dir_name, de->d_name);
    status = lstat(path, &buffer);
    if(S_ISDIR(buffer.st_mode))
    {
       ...
    }
    

    EDIT: Fixed to include directory in lstat path (per el.pescado). As noted by R Samuel Klatchko, you may want to take a whitelist approach (S_ISREG) instead of blacklisting types as they come up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am interested in reading ONLY the TEXT content of a UIWebView. How do
I wrote a custom XML reader because I needed something that would not read
The Kindle has lit a personal interest in reading my various content on it,
I have two threads, one reading streams and producing data-objects from their content. I
I have an image gallery that I created by reading the contents inside a
The current content of this google docs page is: alt text http://www.deviantsart.com/upload/i9k01q.png However, when
I've got an issue with inserting/reading utf8 content from a db. All verifications I'm
I current have the following XML fragment that I'm parsing to read its values
I'm reading some data like speed and curent location using a single ton class....I'm
Love this website! My issue is as follows: I'm reading a zip file that's

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.