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. How to apply a name filter to file name and directory name?
Forum Updated to NodeBB v4.3 + New Features

How to apply a name filter to file name and directory name?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 684 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.
  • M Offline
    M Offline
    MT339M
    wrote on last edited by MT339M
    #1

    I want to apply a name filter to file name and directory name. And I want to list files only.

    QDirIterator directory_iterator("C:\\test\\abc", QStringList() << "*test*.txt", QDir::Files, QDirIterator::Subdirectories);
    

    For example, files exist like as follows.

    C:\test\abc\test1.txt
    C:\test\abc\1test.txt
    C:\test\abc\test\z.txt
    C:\test\abc\z.txt

    and I want list files below.

    C:\test\abc\test1.txt
    C:\test\abc\1test.txt
    C:\test\abc\test\z.txt

    But currently I only get a list like below.

    C:\test\abc\test1.txt
    C:\test\abc\1test.txt

    Is there any option relate to it? Thanks for reading!

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You filter for "test.txt" as filename so what you get is correct. If you also want 'test' then adjust your filter to "test"

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      M 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        You filter for "test.txt" as filename so what you get is correct. If you also want 'test' then adjust your filter to "test"

        M Offline
        M Offline
        MT339M
        wrote on last edited by MT339M
        #3

        @Christian-Ehrlicher

        Thank you for your answer. I want to apply a filter to directory name too.
        I would like to list the files that satisfy the conditions below.

        1. extension is ".txt"
        2. file name or directory name contain a keyword "test"

        But currently it works like below.

        1. extension is ".txt"
        2. file name contain a keyword "test"
        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You have to filter it later by your own.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          M 1 Reply Last reply
          2
          • Christian EhrlicherC Christian Ehrlicher

            You have to filter it later by your own.

            M Offline
            M Offline
            MT339M
            wrote on last edited by
            #5

            @Christian-Ehrlicher
            I got it. Thanks. 👍😁

            1 Reply Last reply
            0

            • Login

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