Results 1 to 11 of 11

Thread: QDir, list all directories?

  1. #1
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QDir, list all directories?

    How can I list/take only directories from a directory?
    E.g.
    Qt Code:
    1. QDir directory = new QDir;
    2. directory.setFolderMode(); //example ! :P
    3. directory.setCurrent("/home/alex/");
    4. for (int i =0; i > directory.count(); i++){
    5. directory.at(i) //mpla mpla...
    6. }
    To copy to clipboard, switch view to plain text mode 
    Very sample code, it's just to understand what i want to achieve...
    Well, that's what i want to do... Take the subfolder names from a specific dir and perform some actions with each one separately...
    Is there any way to do this?
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QDir, list all directories?

    Look at the filters argument to the QDir constructor or QDir::setFilter()

  3. The following user says thank you to ChrisW67 for this useful post:

    hakermania (7th March 2011)

  4. #3
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QDir, list all directories?

    the setfilter takes qstring as argument....Cannot filer the dirs...!
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QDir, list all directories?

    QDir::setFilter() does not take a QString argument, something you would have noticed if you bothered the read the documentation before declaring that it "Cannot filter the dirs...!". Similarly, the filters argument to the constructor does not take a QString argument.

  6. The following user says thank you to ChrisW67 for this useful post:

    hakermania (7th March 2011)

  7. #5
    Join Date
    Oct 2010
    Location
    Belarus
    Posts
    71
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Windows Maemo/MeeGo

    Default Re: QDir, list all directories?

    is setFilter(QDir :: Dirs) what you want?
    Try read Qt documentation before ask stupid question.

  8. The following user says thank you to unit for this useful post:

    hakermania (7th March 2011)

  9. #6
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QDir, list all directories?

    For a reason, I get error out of index or something like this with this solution........ :/
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  10. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDir, list all directories?

    As you said yourself, it's for a reason.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #8
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QDir, list all directories?

    And the code is ...

  12. #9
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QDir, list all directories?

    Qt Code:
    1. QStringList all_dirs;
    2. all_dirs << parent_folder;
    3. QDirIterator directories(parent_folder, QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
    4.  
    5. while(directories.hasNext()){
    6. directories.next();
    7. all_dirs << directories.filePath();
    8. }
    To copy to clipboard, switch view to plain text mode 

    Where parent_folder is the folder whose you want all of his subdirectories.
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  13. #10
    Join Date
    Jul 2015
    Posts
    16
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QDir, list all directories?

    Quote Originally Posted by hakermania View Post
    How can I list/take only directories from a directory?
    E.g.
    Qt Code:
    1. QDir directory = new QDir;
    2. directory.setFolderMode(); //example ! :P
    3. directory.setCurrent("/home/alex/");
    4. for (int i =0; i > directory.count(); i++){
    5. directory.at(i) //mpla mpla...
    6. }
    To copy to clipboard, switch view to plain text mode 
    Very sample code, it's just to understand what i want to achieve...
    Well, that's what i want to do... Take the subfolder names from a specific dir and perform some actions with each one separately...
    Is there any way to do this?
    QDir::at() and QDir::setFolderMode() are not real , are they ? because they're not on Qt 5 at least.
    Last edited by Arshia Aghaei; 1st July 2015 at 05:43.

  14. #11
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QDir, list all directories?

    Look at QDir::entryList() or QDir::entryInfoList() depending on whether you just need the directory names or more info like modification dates, etc.

Similar Threads

  1. Replies: 1
    Last Post: 23rd April 2011, 17:33
  2. Return number of directories in a directories
    By franco.amato in forum Newbie
    Replies: 7
    Last Post: 29th September 2010, 23:29
  3. Return number of directories in a directories
    By franco.amato in forum Qt Programming
    Replies: 1
    Last Post: 29th September 2010, 18:24
  4. Replies: 4
    Last Post: 18th August 2010, 04:23
  5. How to create directories??
    By paranoid_android in forum Qt Programming
    Replies: 3
    Last Post: 9th March 2006, 16:28

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.