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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:02:15+00:00 2026-05-11T19:02:15+00:00

I’m looking to write a portable filesystem scanner, capable of listing all files on

  • 0

I’m looking to write a portable filesystem scanner, capable of listing all files on a given directory path recursively.

To do this, I’m attempting to use cygwin for my compiler, making use of dirent.h and using the template:

#include <dirent.h> 
#include <stdio.h> 

int main(void)
{
  DIR           *d;
  struct dirent *dir;
  d = opendir(".");
  if (d)
  {
    while ((dir = readdir(d)) != NULL)
    {
      // Stuff
    }    
    closedir(d);
  }    
  return(0);
}

But need to add recursive directory searching as well. To do this, my solution was to attempt to opendir() on the next file, and judge the error code to determine if it was successfully opened as a directory (which I would then recurse on) or if it was returned to be ‘not a directory’, which would then be listed as just a file.

I admit it feels very klugey, but I have been unable to find a better method that can retain some portability (not win32), even after hours of searching.

So my simplified solution (some psuedo for simplicity) is looking something like this:

int scan(string startdir)
{
  DIR           *d;
  struct dirent *dir;
  d = opendir(startdir.cstr());
  if (d)
  {
    while ((dir = readdir(d)) != NULL)
    {
      if( NOT '.' AND NOT '..')
      {
        if(temp = opendir(startdir + d) == NULL)
        {
           //FILE OR ERROR
        }else{
          //Opened successfully as a directory, so recurse
          scan(startdir + d->d_name + "\\");
        }
      }
    }
    closedir(d);
  }
  return(0);
}

This is just half rewritten psuedo code to keep it simple, but it seems to work (although I’m very open to suggestions on better ways to do this).

The major issue I’m having, however, is a particular link file ‘c:\cygwin\dev\fd’ which seems to be opening as a directory and recursively opening itself over and over infinitely.

The ‘fd’ file is 4KB, 106 bytes with no extension and is a shortcut that does not point anywhere in Windows.

This error seems to indicate that either this kludgey method is bugged, or there’s a problem in the cygwin implementation that I’m compiling in.

As a short example:

Error Reading: c:\cygwin\dev\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\5\fd\0 No such file or directory

Excluding that directory, the search seems to work well. But I’m not alright with hard coding an exclusion in to the scanner.

If anyone has any ideas, suggestions, solutions, or alternative methods to this problem, your input would be appreciated.

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-05-11T19:02:15+00:00Added an answer on May 11, 2026 at 7:02 pm

    The culprit seems to be that the fd file links into /proc/

    I do not guarantee it to be true, but I am under the impression that this enables the scanner to recursively loop through its own directory structure.

    My efforts with readlink() to address this issue were promising at first, but I’m finding that with deeper levels of scanning, it becomes unreliable and the errors can still occur.

    I am now looking into other ways to achieve this functionality (ie boost::filesystem).

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string

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.