0

I have a QStringList full of file path. But these file path isn't in normal format, i have environment variable in the file path, for example %PATH_OF_VAR%/GEN/abc.txt. I am using fileName but apparently it doesn't work. What I want to do is, I need to get only fileName out of this and save it in another QStringList. When any fileName is deleted from 2nd QStringList respective filepath needs to be automatically deleted from he 1st QStringList

EDIT:

Xmlget.load(String);
QStringList list;
QStringList preset_scr;
QString name;

xmlget.findAndDescend("INIT_SKRIPTE");
while(xmlget.findNext("SKRIPT"))
{
    preset_scr.append(xmlget.getString());
}
for(int i=0;i<preset_scr.count();i++)
{
    QFile file(preset_scr.at(i));
    name = file.fileName();
    list.append(name);
}
qDebug()<<list;

EDIT2: I got trimming working by using QFileInfo instead of QFile, i have no clue how to update 1st QStringList when there is some changes in 2nd QStringList

user5603723
  • 195
  • 2
  • 11

2 Answers2

0

If your file path always look like %PATH_OF_VAR%/GEN/abc.txt then you can fill second list like this:

foreach(const QString& path, preset_scr) {
    QString name = preset_scr.at(i).split("/").last();
    list.append(name); 
}

Second. When you remove string from second list, you can remove path from first list like this (assuming fileName is the name to be removed):

for(int i = preset_scr.count() - 1; i>=0; --i) {
    if(preset_scr.at(i).split("/").last() == fileName)
        preset_scr.removeAt(i);
}
Evgeny
  • 3,910
  • 2
  • 20
  • 37
0

You could try iterate over list and split every string to get only filename:

QStringList preset_scr;
QStringList newList;
QString filename;

for( const auto & s : preset_scr ) {
    filename = s.split("/").last();
    newList.append(filename);
}
Sajmplus
  • 262
  • 4
  • 18
  • I got it split, i am stuck at updating my 1st qstringlist(which is filepath) whenever my 2nd QStringlistis edited – user5603723 Jan 14 '16 at 09:49