There is a directory structure of the form dir/subdir[n]/file[m]
. You must get the dir
directory name, all subdir
directory names, and count the number of files in the subdir
directories. The collected information must be output to QTableWidget
in the format:
DIR| SUBDIR | count_file_SUBDIR ab 5 ac 6 ar 7
At the moment, you can only see how many files are in the DIR
directory (i.e., bypass the entire tree and return the number of files).
The problem is to bypass the subdirectories and display information about them.
void MainWindow::on_btn_download_clicked(bool) { QString src = QFileDialog::getExistingDirectory(); std::string dir; std::string subdir = "SUBDIR";//заглушка int cf = 0;//число файлов в каталоге download_key(src, serial_number, cf); QString ck = QString::number(cf); QString sn = QString::fromStdString(dir); QString tp = QString::fromStdString(subdir); QTableWidgetItem* newItem1 = new QTableWidgetItem(tr("%1").arg(sn)); QTableWidgetItem* newItem2 = new QTableWidgetItem(tr("%1").arg(ck)); QTableWidgetItem* newItem5 = new QTableWidgetItem(tr("%1").arg(tp)); QTableWidgetItem* newItem3 = new QTableWidgetItem(tr("%1").arg(sn)); QTableWidgetItem* newItem4 = new QTableWidgetItem(tr("%1").arg(ck)); QTableWidgetItem* newItem6 = new QTableWidgetItem(tr("%1").arg(tp)); qDebug() << "KEY" << ck << sn << tp << t_col << t_row; ui->key_tableView->setRowCount(t_row + 1); ui->key_tableView_2->setRowCount(t_row + 1); ui->key_tableView->setItem(t_row, t_col, newItem1); ui->key_tableView_2->setItem(t_row, t_col, newItem3); t_col = 1; ui->key_tableView->setItem(t_row, t_col, newItem5); ui->key_tableView_2->setItem(t_row, t_col, newItem6); t_col = 2; ui->key_tableView->setItem(t_row, t_col, newItem2); ui->key_tableView_2->setItem(t_row, t_col, newItem4); ++t_row; t_col = 0; } void download_key(QString src,std::string& dir,int& cf) { QString src_path = QDir(src).absolutePath(); QDirIterator it(src_path,QDir::NoDotAndDotDot| QDir::Files , QDirIterator::Subdirectories); int count_f = 0; while(it.hasNext()) { qDebug() << it.next(); ++count_f; } QString Qserial_number = QDir(src).dirName(); serial_number=Qserial_number.toUtf8().constData(); cf=count_f; }