Qt Centre Forum >
Qt >
Newbie > how to get the list of files without their extensions in a specified directory in Qt
View Full Version : how to get the list of files without their extensions in a specified directory in Qt
sliverTwist
3rd April 2013, 12:45
i want to get all the files that are loacated in a specified directory but without their extensions at the end
i did this :
QDir myDir(mConfigDirectory);
filters << "*.ini";
myDir.setNameFilters(filters);
list = myDir.entryList ();
qDebug()<<list;
but i want to separate the name from the extension and get only names
ChrisW67
3rd April 2013, 12:58
So use the functions in QString to remove the extension for each file name in the list
sliverTwist
3rd April 2013, 13:00
So use the functions in QString to remove the extension for each file name in the list
How is that ? i mean what is the function that remove a file extension ???
Lesiok
3rd April 2013, 13:12
Read about QFileInfo::completeBaseName
sliverTwist
3rd April 2013, 13:31
Read about QFileInfo::completeBaseName
the problem that this methode gives you characters after a suffix not before it !
alainstgt
3rd April 2013, 13:33
use the truncate() method of QString
QString fileName("myFile.new.txt");
qDebug() << fileName; // myFile.new.txt
fileName.truncate(fileName.lastIndexOf('.'));
qDebug() << fileName; // myFile.new
sliverTwist
3rd April 2013, 13:36
Maybe that could help me but still need to truncate from qstringlist !
anda_skoa
3rd April 2013, 14:45
QFileInfo::completeBaseName() should have worked, but you can also try QFileInfo::baseName()
Get the result list as QFileInfoList using QDir::entryInfoList() instead of entryList() and then build you result list from that or use the entry info list for processing and retrieve the base names right there.
Cheers,
_
Lesiok
3rd April 2013, 14:45
the problem that this methode gives you characters after a suffix not before it !
Are You sure ? This from doc : The complete base name consists of all characters in the file up to (but not including) the last '.' character. and example :
QFileInfo fi("/tmp/archive.tar.gz");
QString base = fi.completeBaseName(); // base = "archive.tar"
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.