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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:31:01+00:00 2026-06-12T14:31:01+00:00

I have been beating my head on a wall over this fts_children() question. In

  • 0

I have been beating my head on a wall over this fts_children() question. In the man page, http://www.kernel.org/doc/man-pages/online/pages/man3/fts.3.html, it clearly states As a special case, if fts_read() has not yet been called for a hierarchy,
fts_children() will return a pointer to the files in the logical directory
specified to fts_open(), that is, the arguments specified to fts_open().

Which I take to mean that a linked list of all the files in the current directory are returned. Well, I am finding that not to be the case and I would really appreciate some help in the matter. I expected a linked list to be returned and then I would iterate through it to find the file with the matching file name (the end goal). However, right now, I am just trying to iterate through the linked list (baby steps). Right now, it will return one file and then exit the loop. This does not make sense to me. Any help would very much appreciated!!!

Opening of file system:

char* const path[PATH_MAX] = {directory_name(argv[argc-index]), NULL}; 
            char* name = file_name(argv[argc-index]);

            if ((file_system = fts_open(path, FTS_COMFOLLOW, NULL)) == NULL){
                fprintf(stderr,"%s:%s\n", strerror(errno), getprogname());
                        exit(EXIT_FAILURE);
                 }/*Ends the files system check if statement*/

            /*Displays the information about the specified file.*/
            file_ls(file_system,name, flags);

For clarification, the directory_name parses the inputted path from the user and returns something like /home/tpar44. That directory is then opened.

Searching within the file system:

void
file_ls(FTS* file_system, char* file_name,  int* flags){
    FTSENT* parent = NULL;
    //dint stop = 0;

    parent = fts_children(file_system, 0);

    while( parent != NULL ){
        printf("parent = %s\n", parent->fts_name);
        parent = parent->fts_link;
    }
}

Thanks!

  • 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-12T14:31:02+00:00Added an answer on June 12, 2026 at 2:31 pm

    I think this is entirely by design.

    …that is, the arguments specified to fts_open()…

    What it says is that it will list the root elements in the path_argv parameters for your convenenience. It treats the path_argv array as a logical directory itself.

    In other words this:

    int main(int argc, char* const argv[])
    {
        char* const path[] = { ".", "/home", "more/root/paths", NULL }; 
    
        FTS* file_system = fts_open(path, FTS_COMFOLLOW | FTS_NOCHDIR, &compare);
    
        if (file_system)
        {
            file_ls(file_system, "", 0);
            fts_close(file_system);
        }
        return 0;
    }
    

    Will output

    parent = .
    parent = /home
    parent = more/root/paths
    

    Which, in fact, it does (see http://liveworkspace.org/code/c2d794117eae2d8af1166ccd620d29eb).

    Here is a more complete sample that shows complete directory traversal:

    #include<stdlib.h>
    #include<stdio.h>
    #include<sys/types.h>
    #include<sys/stat.h>
    #include<fts.h>
    #include<string.h>
    #include<errno.h>
    
    int compare (const FTSENT**, const FTSENT**);
    
    void file_ls(FTS* file_system, const char* file_name, int* flags)
    {
        FTSENT* node = fts_children(file_system, 0);
    
        if (errno != 0)
            perror("fts_children");
    
        while (node != NULL)
        {
            // TODO use file_name and flags
            printf("found: %s%s\n", node->fts_path, node->fts_name);
            node = node->fts_link;
        }
    }
    
    int main(int argc, char* const argv[])
    {
        FTS* file_system = NULL;
        FTSENT* node = NULL;
    
        if (argc<2)
        {
            printf("Usage: %s <path-spec>\n", argv[0]);
            exit(255);
        }
    
        char* const path[] = { argv[1], NULL }; 
        const char* name = "some_name";
    
        file_system = fts_open(path, FTS_COMFOLLOW | FTS_NOCHDIR, &compare);
    
        if (file_system)
        {
            file_ls(file_system, name, 0); // shows roots
    
            while( (node = fts_read(file_system)) != NULL)
                file_ls(file_system, name, 0); // shows child elements
    
            fts_close(file_system);
        }
        return 0;
    }
    
    int compare(const FTSENT** one, const FTSENT** two)
    {
        return (strcmp((*one)->fts_name, (*two)->fts_name));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well, I have been beating my head over this one for some time now,
I have been beating my head in the wall all evening on this, can
So, I've been beating my head against the wall of this issue for several
I've been beating my head against this for awhile to no avail. I have
I have an odd problem that I've been beating my head into a wall
Been beating my head against a wall trying to get this to work -
I've been beating my head against the wall trying to get this to work,
I'm nearly finished with this project but I have been beating my head against
I've been beating my head against the wall on this for a few hours.
I've been beating myself over the head with this app migration for a few

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.