Checking if a folder exists (and creating folders) in Qt, C++

后端 未结 5 669
深忆病人
深忆病人 2020-12-04 09:07

In Qt, how do I check if a given folder exists in the current directory?
If it doesn\'t exist, how do I then create an empty folder?

5条回答
  •  伪装坚强ぢ
    2020-12-04 09:32

    If you need an empty folder you can loop until you get an empty folder

        QString folder= QString ("%1").arg(QDateTime::currentMSecsSinceEpoch());
        while(QDir(folder).exists())
        {
             folder= QString ("%1").arg(QDateTime::currentMSecsSinceEpoch());
        }
        QDir().mkdir(folder);
    

    This case you will get a folder name with a number .

提交回复
热议问题