how can i list the files in a directory
-
I want to list the files that are present in a directory.
-
@Nathan-Miguel said in how can i list the files in a directory:
I want to list the files that are present in a directory.
-
@JKSH Good worked, but would somehow print this value without quotation marks and dots
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); //VAR QString rootDir = qApp->applicationDirPath(); QString data = "/data"; QDir mkDir; bool autostart = QDir(QDir::homePath()+"/.config/autostart").exists(); QDir test(rootDir+data); QStringList testlist = test.entryList(); QString testout = testlist.join(""); qDebug() << testout; return 0; }
-
@Nathan-Miguel said in how can i list the files in a directory:
print this value without quotation marks
https://doc.qt.io/qt-5/qdebug.html#operator-lt-lt-16
QString testout = testlist.join("");
What are you trying to do with this line?
-
@Nathan-Miguel Quotation marks come from qDebug and are not part of the actual string...
You can verify this using std::cout instead of qDebug. -
@Nathan-Miguel
Look, the "dots" aren't part of a file name, they are the.
and the..
entries in the directory, The other two are filenames. You are choosing to print them out all touching each other (testlist.join("")
). Clearly that has nothing to do with your "want to set to open a file inside the folder". You can access indvidual files via each element inentryList()
orentryInfoList()
, as you please.