Hi,
Maybe with this:
return;
int pos;
int pos2;
grupToDelete = "SomeThing";
while (!in.atEnd())
{
if (line.contains("[") && line.contains("]")) //If it is a group
{
pos = line.indexOf("[");
pos2 = line.indexOf("]");
currentGroup = line.mid(pos+1,pos2-1); //Get the group
}
if (currentGroup != grupToDelete) //If the line is not the group to delete
{
temp.append(line); //Move the lines to temp
}
}
//Temp will now have all the lines but those to delete
//So save temp to out.ini
return;
for (pos = 0; pos <= temp.count()-1;pos++)
out << temp[pos] << "\n";
QFile::remove("ini.ini");
//Remove the old file QFile::rename("out.ini",
"in.ini");
//Rename out to in
QFile file("in.ini");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream in(&file);
QString currentGroup;
QStringList temp;
int pos;
int pos2;
QString grupToDelete;
grupToDelete = "SomeThing";
while (!in.atEnd())
{
QString line = in.readLine();
if (line.contains("[") && line.contains("]")) //If it is a group
{
pos = line.indexOf("[");
pos2 = line.indexOf("]");
currentGroup = line.mid(pos+1,pos2-1); //Get the group
}
if (currentGroup != grupToDelete) //If the line is not the group to delete
{
temp.append(line); //Move the lines to temp
}
}
//Temp will now have all the lines but those to delete
//So save temp to out.ini
QFile ofile("out.ini");
if (!ofile.open(QIODevice::WriteOnly | QIODevice::Text))
return;
QTextStream out(&ofile);
for (pos = 0; pos <= temp.count()-1;pos++)
out << temp[pos] << "\n";
QFile::remove("ini.ini"); //Remove the old file
QFile::rename("out.ini","in.ini"); //Rename out to in
To copy to clipboard, switch view to plain text mode
I have no clue if an INI group can have subgroups.... If so... It will not remove any subgroups (like a tree) just the specified in grupToDelete.. You can make it a function so you can delete more than one group though.
Test it first!!!!
Bookmarks