-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
77 lines (68 loc) · 2.27 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
const QString fileDirectory = QFileDialog::getExistingDirectory(this);
if (!fileDirectory.isEmpty()) {
ui->lineEdit->clear();
ui->lineEdit->setText(fileDirectory);
ui->lineEdit->setReadOnly(true);
}
}
void MainWindow::on_pushButton_2_clicked()
{
start:
if (ui->lineEdit->isReadOnly()) {
const QString fileDirectory = ui->lineEdit->text();
QDir currentDirectory = fileDirectory;
QStringList theList;
theList = currentDirectory.entryList(QDir::Files);
foreach (QString fileName, theList) {
QStringList splittedName = fileName.split(" ");
if (splittedName.size() > 0) {
if (splittedName[0].endsWith('.') && splittedName[0].size() >= 2) {
QStringList split2 = splittedName[0].split('.');
if (split2.size() == 2 && confirmOnlyIntegersExist(split2[0])) {
QString newName;
for (int i = 1; i < splittedName.size(); i++) {
if (i != splittedName.size() && i != 1) {
newName += " " + splittedName[i];
}else{
newName += splittedName[i];
}
}
currentDirectory.rename(fileName, newName);
}
}
}
}
QMessageBox::information(this,
"Rename Success",
"The list numbers \nhave been successfully \nbeen removed.");
} else
{
on_pushButton_clicked();
goto start;
}
}
bool MainWindow::confirmOnlyIntegersExist(QString name)
{
QString numbers = "0123456789";
for (int i = 0; i < name.length(); i++) {
if (!numbers.contains(name[i]))
return false;
}
return true;
}