-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.py
51 lines (42 loc) · 1.39 KB
/
functions.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
import os
###############################################
# Clear prompt of CLI
###############################################
clear = lambda: os.system('cls')
###############################################
# Add a prefix to files
###############################################
def prefixfiles():
clear()
prefix = input("Prefix: ")
for filename in os.listdir("."):
os.rename(filename, prefix + filename)
###############################################
# Rename complete names and add a counter
###############################################
def filescounter(param):
clear()
renamefile = input("-> New Name: ")
listfile = []
listfile = os.listdir(".")
if param == 21:
for filename in listfile:
fileindex = listfile.index(filename)
os.rename(filename, renamefile + str(fileindex+1) + filename[len(filename)-4:])
else:
matchtext = input("-> Match Word: ")
for filename in listfile:
fileindex = listfile.index(filename)
if filename.startswith(matchtext):
os.rename(filename, renamefile + str(fileindex+1) + filename[len(filename)-4:])
###############################################
# Replace/Remove Word
###############################################
def rrename():
clear()
renamefile = input("-> New Word: ")
matchtext = input("-> Old Word: ")
listfile = []
listfile = os.listdir(".")
for filename in listfile:
os.rename(filename, filename.replace(matchtext,renamefile))