Results 1 to 4 of 4

Thread: QDir::entryList() get absolute path

  1. #1
    Join Date
    Mar 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QDir::entryList() get absolute path

    edit: (Maybe this should have been posted at the "Newbie" section)

    Hi

    I'm trying to get all folder names with absolute paths. My question is maybe kinda simple, does my implementation have any pitfalls?

    Qt Code:
    1. QDir dir("R:/");
    2. dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot).replaceInStrings(QRegExp("^"),dir.absolutePath())
    To copy to clipboard, switch view to plain text mode 

    QDir::entryList() only returns a QStringList containing directory names without full paths.

    So my simple one line solution would be using QStringList::replaceInStrings() with
    parameters QRegExp("^") and dir.absolutePath(),
    which should add the string "R:/" as a prefix to each directory entry, giving me full paths.
    As I said, does my solution have any pitfalls like for example if the QRegExp("^") might get applied elsewhere in the string instead of only in the beginning as a prefix?

    I have tried naming folders with spaces, symbols and it seems to me that it works.
    Maybe I'm just paranoid but I would love to hear about your expert opinions . Much appreciated.

    Also, would be nice if you guys and gals could share your favorite solutions.

    (It's a pity IMHO that QDir::absoluteEntryList() doesn't exist)

    Thanks for reading

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QDir::entryList() get absolute path

    What's about using QDir::entryInfoList() and then use them. If you need a QStringList with the path then iterate over the list and use e.g. QFileInfo::absolutePath().

  3. #3
    Join Date
    Mar 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDir::entryList() get absolute path

    Yeah I thought about it first, to iterate through each QFileInfo and let that handle the absolute paths return, maybe that is safer.

  4. #4
    Join Date
    Apr 2011
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDir::entryList() get absolute path

    [link]http://doc.trolltech.com/latest/qdir.html#absoluteFilePath[/link]
    maybe it could be useful, i hope it works for you

Similar Threads

  1. QDir - Entrylist, sort
    By bismitapadhy in forum Qt Programming
    Replies: 5
    Last Post: 28th January 2010, 07:27
  2. Replies: 8
    Last Post: 17th October 2009, 09:10
  3. QDir entryList performing slowly
    By bunjee in forum Qt Programming
    Replies: 3
    Last Post: 8th October 2009, 17:21
  4. QDir::entryList() on linux
    By JeanC in forum Qt Programming
    Replies: 3
    Last Post: 3rd March 2008, 14:46
  5. qdir and entrylist
    By mattia in forum Newbie
    Replies: 1
    Last Post: 28th November 2007, 11:13

Tags for this Thread

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.