Results 1 to 4 of 4

Thread: QFileInfo Creation

  1. #1
    Join Date
    Jul 2008
    Posts
    139
    Thanks
    9
    Thanked 18 Times in 15 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default QFileInfo Creation

    Hi,
    I know QFileInfo can get the creation date of a file. Is there an effiecient method in for finding the oldest file in a directory using Qt functions?. The directory will have a maximum of 125 files in it. I know in linux I can use this ls -lat | grep ^- | tail -1 | head -1. but I prefer not using this method.
    I need the speed to be fast. Any suggestions?
    Thank you.

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFileInfo Creation

    I think this QDir::entryInfoList should help you.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFileInfo Creation

    an example
    Qt Code:
    1. ...
    2. QDir dir("d:/");
    3. QStringList entities = dir.entryList(QDir::Files, QDir::Time);
    4. qDebug() << entities;
    5. ...
    To copy to clipboard, switch view to plain text mode 
    a last file is oldest.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  4. #4
    Join Date
    May 2009
    Posts
    62
    Thanks
    2
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFileInfo Creation

    Not quite, QDir::Time sorts by modification date, not creation date. You will have to read all QFileInfo's and do the comparison yourself:

    Qt Code:
    1. QDir dir("d:/");
    2. QFileInfo oldest;
    3. foreach (QFileInfo fileInfo, dir.entryInfoList())
    4. {
    5. if (oldest.filePath().isEmpty() || fileInfo.created() < oldest.created())
    6. {
    7. oldest = fileInfo;
    8. }
    9. }
    10. qDebug() << "Oldest file is: " << oldest.filePath();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. How to avoid creation of MOC files on each compilation
    By nileshsince1980 in forum Qt Programming
    Replies: 4
    Last Post: 29th May 2009, 09:00
  2. Replies: 1
    Last Post: 2nd March 2009, 20:32
  3. QFileInfo and lastModified for directory on Mac OS X
    By kghose in forum Qt Programming
    Replies: 1
    Last Post: 22nd October 2008, 21:45
  4. QFileInfo and lastModified for directory
    By kghose in forum Qt Programming
    Replies: 4
    Last Post: 28th July 2008, 16:07
  5. Storing/Reading item creation date
    By maverick_pol in forum Qt Programming
    Replies: 2
    Last Post: 26th May 2008, 09:19

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.