qt 获取本地文件夹、文件路径

//获取文件夹路径
QString srcDirPath = QFileDialog::getExistingDirectory( this, "choose Directory",  "/");
   if (srcDirPath.isEmpty())
   {
       return ;
   }
//创建文件夹
QDir dir;
if (!dir.exists(path))//检查文件夹是否存在   path为文件夹路径
{
	bool res = dir.mkpath(path);//没有就创建
	if(res)
	{
		QMessageBox::about(this, "tips", "创建成功");//创建成功时,显示此提示框
	}
	else
	{
		QMessageBox::about(this, "tips", "创建失败");//创建失败时,显示此提示框
	}
}
//获取文件路径
QString str = QFileDialog::getOpenFileName();
if(str.isEmpty())
{
    return;
}
//文件改名或移动
bool res = QFile::rename(src,pathStr); //src改名为或移动到pathStr
if(res)
{
	QMessageBox::about(this, "tips", "改名成功!");//成功显示次提示框
}
else
{
	QMessageBox::about(this, "tips", "改名失败!");//失败显示次提示框
}

你可能感兴趣的:(Qt,文件操作,文件夹选择,路径管理,文件重命名,目录创建)