Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDir - Filter by file name, not extension
Forum Update on Monday, May 27th 2025

QDir - Filter by file name, not extension

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 5.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bluscape
    wrote on 24 Feb 2014, 12:33 last edited by
    #1

    I would like to list the files in a directory with similar names (not extension).

    For example, list all files that sounds like "Apple". (Apple1.txt, Apple2.txt, Apple3.txt)

    To list files by extension I would to this:

    @
    QStringList nameFilter("*.txt");
    QDir directory("/home/");
    QStringList FilesAndDirectories = directory.entryList(nameFilter);
    @

    But how do I list by file name?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 24 Feb 2014, 12:43 last edited by
      #2

      @
      QStringList nameFilter("Apple*");
      @

      (Z(:^

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hpollak
        wrote on 24 Feb 2014, 14:37 last edited by
        #3

        Your default filter is set to NoFilter!!

        see definition:

        QStringList QDir::entryList(const QStringList & nameFilters, Filters filters = NoFilter, SortFlags sort = NoSort) const

        so you can specify the Filters see:
        "QDir::Filters":http://qt-project.org/doc/qt-5/qdir.html#Filter-enum

        at the link is allso an example :-)

        best regards

        Harry

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bluscape
          wrote on 24 Feb 2014, 20:29 last edited by
          #4

          @sierdzio

          It worked perfectly. Thanks!

          1 Reply Last reply
          0

          1/4

          24 Feb 2014, 12:33

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved