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 8177307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:28:32+00:00 2026-06-06T23:28:32+00:00

Alright, so I am having some issues. Here is my code (opendir() called before

  • 0

Alright, so I am having some issues. Here is my code (opendir() called before this):

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

        lstat(dp->d_name, &stbuf);

        printf("%s: ", dp->d_name);

        if( S_ISDIR(stbuf.st_mode) )
            puts("Directory");
        else if ( S_ISREG(stbuf.st_mode) )
            puts("File");
        else if ( S_ISCHR(stbuf.st_mode) )
            puts("Character Device");
        else if ( S_ISBLK(stbuf.st_mode) )
            puts("Block Device");
        else if ( S_ISFIFO(stbuf.st_mode) )
            puts("Fifo");
        else if ( S_ISLNK(stbuf.st_mode) )
            puts("Link");
        else
            puts("Socket");
    }
    return;
}

I am reading through a directory and determining what the file type’s are inside. The only problem is that this will always print “Directory” and I believe it has something to do with the call to lstat. I’m not exactly sure how to change it appropriately.

  • 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-06T23:28:33+00:00Added an answer on June 6, 2026 at 11:28 pm
    lstat(dp->d_name, &stbuf);
    

    Thing is dp->d_name contains only the name of the file, not the full path. So it probably fails, but you can’t notice since you don’t test its return value.

    You need to prepend the path of the directory (i.e., what you passed to opendir).

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

Sidebar

Related Questions

Alright, I'm having some issues and I believe it's a CSS one. Here is
I'm having some issues getting the following code to compile: GLint iModelMatrix = glGetUniformLocation(m_shaderProgramID,
Alright, I'm having a hard time explaining this, let me know if I should
Alright I don't see why this isnt working. It seems pretty simple. Here is
Alright I created some custom classes for my project sourced from this tutorial ,
Alright, so I got this code for gluLookAt: lookAt = new Vector3f(-player.pos.x, -player.pos.y, -player.pos.z);
Alright, I have some weird behavior and this question goes to the people out
I'm having some trouble sending $_FILES by cURL - the files get transferred alright
Alright I am having a world of difficulty tracking down this memory leak. When
Alright, I'm having an issue with logic flow. For some reason one of the

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.