-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenamer.cpp
39 lines (31 loc) · 1.19 KB
/
renamer.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
#include "renamer.h"
#include <QDir>
#include <QThread>
Renamer::Renamer(QObject *parent) : QObject(parent)
{
}
void Renamer::startRenamer(QString folder_name)
{
// Create a QDir object
QDir dir(folder_name);
// Filter to display only files
dir.setFilter(QDir::Files);
// File counter
int file_count = 0;
// if a folder was selected, check if the folder exists
if(dir.exists()) {
// if the folder selected exists, start the rename process
foreach (QFileInfo file, dir.entryInfoList()) {
// Emit a signal to the main thread telling that a file was renamed
emit renamedFile(file.absoluteFilePath());
// Add 1 to the file counter
file_count += 1;
}
} else {
// if the folder selected doesn't exist, inform the user about it with a messagebox
emit error("Folder doesn't exist",
"The folder you selected does not exist. Please select a valid folder.");
}
emit finished("Successfully renamed " + QString::number(file_count) + " files. " + QString::number(dir.count()),
"Successfully finished renaming " + QString::number(file_count) + " files.");
}