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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:36:37+00:00 2026-06-10T11:36:37+00:00

I have a little trouble using the Qt functions to walk through a directory

  • 0

I have a little trouble using the Qt functions to walk through a directory recursively.
What I’m trying to do:

Open a specified directory.
Walk through the directory, and each time it encounters another directory, open that directory, walk through the files, etc.

Now, how I am going about this:

QString dir = QFileDialog::getExistingDirectory(this, "Select directory");
if(!dir.isNull()) {
    ReadDir(dir);
}

void Mainwindow::ReadDir(QString path) {
    QDir dir(path);                            //Opens the path
    QFileInfoList files = dir.entryInfoList(); //Gets the file information
    foreach(const QFileInfo &fi, files) {      //Loops through the found files.
        QString Path = fi.absoluteFilePath();  //Gets the absolute file path
        if(fi.isDir()) ReadDir(Path);          //Recursively goes through all the directories.
        else {
            //Do stuff with the found file.
        }
    }
}

Now, the actual problem I’m facing: Naturally, entryInfoList would also return the ‘.’ and ‘..’ directories. With this setup, this proves a major problem.

By going into ‘.’, it would go through the entire directory twice, or even infinitely (because ‘.’ is always the first element), with ‘..’ it would redo the process for all folders beneath the parent directory.

I would like to do this nice and sleek, is there any way to go about this, I am not aware of? Or is the only way, that I get the plain filename (without the path) and check that against ‘.’ and ‘..’?

  • 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-10T11:36:38+00:00Added an answer on June 10, 2026 at 11:36 am

    You should try to use the QDir::NoDotAndDotDot filter in your entryInfoList, as described in the documentation.

    EDIT

    • Don’t forget to add a QDir::Files, or QDir::Dirs or QDir::AllFiles to pick up the files and/or directories, as described in this post.

    • You may also want to check this previous question.

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

Sidebar

Related Questions

Little trouble in using css, in the below code, i have used odd and
I am having a little trouble using addoperationwithblock in Cocoa. Let's say I have
I`m writing a chat using WinSock2 and WinAPI functions. And I have a little
I wrote few custom view helpers but I have a little trouble using them.
I have a little trouble understanding scope and lifetime using javaScript and jQuery. I
I a having a little trouble with vector or array operations. I have three
I'm having a trouble with this little problem. Let's say, I have an array,
I'm a jQuery newbie, and I have trouble with a little script I created.
I have little doubt about string reading in C. string reading functions like gets,
I'm new to Symfony2 (with knowledge in 1.2-1.4) and having little trouble trying to

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.