-
Notifications
You must be signed in to change notification settings - Fork 0
/
bulkrename.py
53 lines (41 loc) · 1.42 KB
/
bulkrename.py
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
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import sys
import os
import bulkrename_GUI
class BulkRenameQT(QDialog, bulkrename_GUI.Ui_bulkrename):
def __init__(self):
QDialog.__init__(self)
self.setupUi(self)
# assign actions to all buttons
self.start.clicked.connect(self.start_button)
def start_button(self, closeEvent):
file_destination = self.URL.toPlainText()
rename_text = self.Append.toPlainText()
i = 0
a = 0
if file_destination == "":
file_destination = os.getcwd()
path = file_destination + "/"
for filename in os.listdir(path):
extension = os.path.splitext(filename)[1]
print(filename)
if filename.endswith('.py'):
i += 1
elif os.path.isdir(filename):
i += 1
else:
my_dest = rename_text + str(a) + extension
my_source = path + filename
my_dest = path + my_dest
os.rename(my_source, my_dest)
a += 1
i += 1
quit_msg = QMessageBox.question(self, "Complete", "Rename is complete, close app?", QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
if quit_msg == QMessageBox.Yes:
exit()
app = QApplication(sys.argv)
bulkrenameQT = BulkRenameQT()
bulkrenameQT.show()
app.exec_()