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. Read files from folder
Qt 6.11 is out! See what's new in the release blog

Read files from folder

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 402 Views 2 Watching
  • 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.
  • S Offline
    S Offline
    Sikarjan 0
    wrote on last edited by
    #1

    Hi there!

    I found a post with my exact question but the solution does not seem to work with the current Qt version (Qt 6.3.2 for macOS)
    Re: How to read all files from a selected directory and use them one by one?

    Here is what I did:

    QDir dir(url.toString());
    QFileInfoList notes = dir.entryInfoList(QStringList() << "*.txt", QDir::Files, QDir::Name);
    qDebug() << dir.path() << notes.size();
    

    The result of qDebug is

    "file:///Users/xxx/Documents/Cloud/Notes" 0
    

    So the path is correct and the folder Notes contain four txt files. Why is my qFileInfoList empty? Can anybody tell me what I did wrong in getting a list of file names from a folder?

    Thanks!

    M 1 Reply Last reply
    0
    • S Sikarjan 0

      Hi there!

      I found a post with my exact question but the solution does not seem to work with the current Qt version (Qt 6.3.2 for macOS)
      Re: How to read all files from a selected directory and use them one by one?

      Here is what I did:

      QDir dir(url.toString());
      QFileInfoList notes = dir.entryInfoList(QStringList() << "*.txt", QDir::Files, QDir::Name);
      qDebug() << dir.path() << notes.size();
      

      The result of qDebug is

      "file:///Users/xxx/Documents/Cloud/Notes" 0
      

      So the path is correct and the folder Notes contain four txt files. Why is my qFileInfoList empty? Can anybody tell me what I did wrong in getting a list of file names from a folder?

      Thanks!

      M Offline
      M Offline
      mpergand
      wrote on last edited by mpergand
      #2

      @Sikarjan-0

      I think you should use url.path()

      S 1 Reply Last reply
      4
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #3

        Not sure why you use a file:// URI when a basic path would be acceptable.

        That URL does not specify the Windows drive on which \Users\xxx\Documents\Cloud\Notes is alleged to exist. This may fail if the current working directory of the process is not on C: (typically where the Users exists). Try file:///C:/Users/xxx/Documents/Cloud/Notes.

        It may also fail if the "folder" Cloud or Notes are the result of some file sync software redirection. So, for example, files may appear in Windows Explorer that are not actually on the file system and therefore invisible to QDir.

        1 Reply Last reply
        2
        • M mpergand

          @Sikarjan-0

          I think you should use url.path()

          S Offline
          S Offline
          Sikarjan 0
          wrote on last edited by
          #4

          @mpergand thanks that was the issue.

          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