PDA

View Full Version : Get directory of QString



Astrologer
23rd April 2010, 12:01
Hi there. I have a QString which contains a full path to a file. I need extract the directory out of it. And then I need create the directory with certain name specified by the second QString.



QString full_path_name("c:\\folder1\\mynewJPG.jpg");


I want the final QString to be like this - "c:\\folder1\\myNewJPG.files\\". Thank you so much in advance.

Astrologer
23rd April 2010, 12:10
Solved.



QString current_jpg_name("c:\\myFolder\\jpg.jpg");
QFileInfo fi(current_jpg_name);
QString folder_name = fi.baseName();
folder_name.append(".files"); // "jpg.files"

QDir tmp_dir(fi.dir());// "c:\\myFolder\\"
tmp_dir.mkdir(folder_name); // "c:\\myFolder\\jpg.files\\"