Results 1 to 5 of 5

Thread: List all XML files in a directory

  1. #1
    Join Date
    Feb 2010
    Posts
    61
    Thanks
    18
    Qt products
    Qt4
    Platforms
    MacOS X

    Default List all XML files in a directory

    i would like to read all XML files of a directory. To this end I use the entryList function of QDir.

    I have seen that you precise a filter to display files only, but is there a way to be more precise and display only .xml documents ?

    For the moment I use the following instruction:

    Qt Code:
    1. QStringList entries = dir.entryList(QDir::Files);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2008
    Location
    France
    Posts
    149
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: List all XML files in a directory

    Use that function:
    Qt Code:
    1. QDir::entryList ( const QStringList & nameFilters, Filters filters = NoFilter, SortFlags sort = NoSort ) const
    To copy to clipboard, switch view to plain text mode 
    Simple example:
    Qt Code:
    1. QDir dir(yourPath);
    2. QStringList filters;
    3. filters << "*.xml"; //append your xml filter. You can add other filters here
    4.  
    5. foreach ( QString file, dir.entryList(filters, QDir::Files) )
    6. // do wathever with *.xml files
    To copy to clipboard, switch view to plain text mode 
    Have look as well at http://doc.trolltech.com/4.6/qdir.html#setNameFilters
    Last edited by toutarrive; 29th March 2010 at 22:50.

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

    ouekah (30th March 2010)

  4. #3
    Join Date
    Aug 2015
    Posts
    1
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: List all XML files in a directory

    How do I get the current file name and path within the foreach loop? I need to draw information from each one and put it into a vector.
    Qt Code:
    1. QDir dir(path);
    2. QStringList filters;
    3. filters << "*.txt";
    4. foreach(QString file, dir.entryList(filters, QDir::Files)){
    5. QFile mine(/*file path? */);
    6. mine.open(QIODevice::ReadOnly);
    7. // stuff here
    8. }
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Feb 2014
    Posts
    60
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: List all XML files in a directory

    For file name and path use QFileInfo class.

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

    MaliciousMatrix (30th August 2015)

  7. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: List all XML files in a directory

    Quote Originally Posted by anbu01 View Post
    For file name and path use QFileInfo class.
    Exactly. Loop over entryInfoList() to get these.

    Cheers,
    _

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

    MaliciousMatrix (30th August 2015)

Similar Threads

  1. Count files of a directory
    By radu_d in forum Qt Programming
    Replies: 6
    Last Post: 27th March 2012, 03:17
  2. Display files of a Directory
    By mansu in forum Qt Programming
    Replies: 2
    Last Post: 8th March 2009, 15:08
  3. directory and files
    By rmagro in forum Qt Programming
    Replies: 2
    Last Post: 16th September 2008, 13:40
  4. Replies: 1
    Last Post: 4th August 2008, 09:02
  5. trace new files in a directory
    By Fastman in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2007, 12:04

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.