2012-07-10 73 views
0

我正在使用下面的代碼在現有的「遊戲」文件夾中創建一個新文件夾,但它只是沒有製作文件夾。如何在手機內存中創建新文件夾諾基亞Qt

QDir dir("C:/Games/MyGame"); 
if(!dir.exists()) 
{ 
    dir.mkdir("C:/Games/MyGame"); 
} 
else 
{ 
    qDebug()<<dir.absolutePath() + " exists"; 
} 

回答

0

確保在C:/有遊戲文件夾[編程方式檢查一個QDir()是否存在。(「C:/遊戲/)是返回true。

而且還確保您的C:/文件夾doesn't have any file named Games, Because if you have file with same name, the exists function will return false even if the folder is present! 。而mkdir將返回false!

下面這段代碼應該創建指定的目錄,如果它不存在。

if (QDir().exists("C:/Games/MyGame")) 
{ 
    qDebug()<<dir.absolutePath() + " exists"; 
} 

else 
{ 
    QDir().mkdir("C:/Games/MyGame"); 
}