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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:19:04+00:00 2026-06-17T00:19:04+00:00

The following code sample allows you to know all the files within a directory.

  • 0

The following code sample allows you to know all the files within a directory.

DIR *pDIR;
struct dirent *entry;

if( (pDIR = opendir(path)) != NULL )
{
    while( (entry = readdir(pDIR)) != NULL )
    {
    if( strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0 )
    {
            string path_to_file(path);
            path_to_file.append("/");
            path_to_file.append(entry->d_name);

            cout << path_to_file << endl;
        }
    }
}

The files are not listed in alphabetical order: what determines the order in which they are listed?

  • 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-17T00:19:05+00:00Added an answer on June 17, 2026 at 12:19 am

    As James has said, there is nothing specifying the order. It is entirely up to the filesystem to order the files in any order it likes. In Windows NTFS (and OS/2’s HPFS) files are indeed ordered in alphabetical order (in a form of binary tree, making it easy to search for files by name). In the “DOS” FAT file-system, the files are in the order they were created, and if a file is deleted, that “slot” is used for the next file that is created. In the Linux operating systems ext{2,3,4} is the most commonly used, which I believe it is similar to FAT, but the exact structure isn’t the same.

    There are dozens of other filesystems (for Linux there are at least half a dozen, and almost every OS that I haven’t mentioned by name has its own variation), which all have their own ways of doing things. If you want to reliably have the files sorted in any particular order, you will have to sort them.

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

Sidebar

Related Questions

The following code sample (also at http://jsfiddle.net/MZwBS/ ) var items = []; items.push({ example:
The goal of the following code sample is to read the contents of $target
Given the following code sample: uint8_t i, in, ni; i = in = 2;
I have the following code sample that im trying to wrap my head around
I have the following code sample: float val = 16777216.0F; var badResult = Convert.ToDecimal(val);
I have the following sample code and noticed that if I attempt to use
I wrote the following sample code to see how ARC works @property (nonatomic, weak)
Consider the following HTML/css code sample: <div id="container"> <div id="up">Text<br />Text<br />Text<br /></div> <div
I have the following sample code which doesn't seem to want to run. import
I have a Dictionary bound to DataGridView by using following sample code. DataGridView bound

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.