Skip to content

Commit dea6acb

Browse files
committed
improve: files with the same file name will be renamed in goal path
1 parent 4b18b57 commit dea6acb

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

filewatchermodule.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,20 @@ void FileWatcherModule::printFile(QString filePath){
191191
}
192192

193193
const QString newPath = mMoveToPath + "/" + info.fileName();
194+
195+
196+
QFileInfo goalFileInfo(newPath);
197+
QFile goalFile(newPath);
198+
199+
if(goalFile.exists()){
200+
QString newFileName = goalFileInfo.baseName() + "_renamed_cause_multiple_" + QDateTime::currentDateTime().toString("dd_MM_yyyy_hh_mm_ss") + "." + goalFileInfo.completeSuffix();
201+
goalFile.rename(goalFileInfo.absolutePath() + QDir::separator() + newFileName);
202+
qDebug() << "File renamed cause its already existing in the goal directory - new file name: " + newFileName;
203+
}
204+
194205
if(file.copy(newPath))
195206
file.remove();
207+
196208
qDebug() << info.fileName() << " moved to " << mMoveToPath;
197209
}
198210

main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QS
4141

4242
int main(int argc, char *argv[])
4343
{
44+
#ifndef QT_DEBUG
4445
qInstallMessageHandler(myMessageOutput);
46+
#endif
47+
4548
QApplication a(argc, argv);
4649
a.setApplicationName("QFileWatcher");
47-
a.setApplicationVersion("0.3");
50+
a.setApplicationVersion("0.4");
4851

4952
QTranslator qtTranslator;
5053
if (qtTranslator.load(QLocale::system(), "qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath))){

mainwindow.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class MainWindow : public QMainWindow
2020
private slots:
2121
void on_pushButton_addWatcher_clicked();
2222
void on_pushButton_choosePDPrinterPath_clicked();
23-
2423
void on_checkBox_autostart_stateChanged(int arg1);
2524

2625
private:

0 commit comments

Comments
 (0)