Read files from folder
-
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" 0So 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!
-
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" 0So 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!
I think you should use url.path()
-
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\Notesis alleged to exist. This may fail if the current working directory of the process is not on C: (typically where the Users exists). Tryfile:///C:/Users/xxx/Documents/Cloud/Notes.It may also fail if the "folder"
CloudorNotesare 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. -
I think you should use url.path()
@mpergand thanks that was the issue.