copyfile - QT Splitting files inside folder into different subfolders -
copyfile - QT Splitting files inside folder into different subfolders -
i have next code re-create files subfolders. first 20 pictures copied instead of 1-20 first folder, 21-40 sec folder , 41-60 3rd folder:
qdir dir(ui->lineedit->text()); qlist<qstring> filenamelist; qfileinfolist files = dir.entryinfolist(); foreach(const qfileinfo &fi, files) { if(!fi.isdir()) { if (fi.filename().endswith(".jpg")) { filenamelist.append(fi.filename()); } } } int parts = (int) (filenamelist.size()) / ui->spinbox->value(); qdebug() << "parts=" << parts; (int = 0; < parts; i++) { qdir().mkdir(ui->lineedit->text() + qstring("/part%1").arg(i + 1)); (int l = 0; l < ui->spinbox->value(); l++) { qfile::copy(ui->lineedit->text() + "/" + filenamelist.at(l), ui->lineedit->text() + qstring("/part%1").arg(i + 1) + "/" + filenamelist.at(l)); } }
the problem indexing of filenamelist
. indexing 0
l
causes re-create first files. should :
int index = i*ui->spinbox->value() + l; qfile::copy(ui->lineedit->text() + "/" + filenamelist.at(index), ui->lineedit->text() + qstring("/part%1").arg(i + 1) + "/" + filenamelist.at(index));
qt copyfile
Comments
Post a Comment