-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddPrefixFolder.py
31 lines (25 loc) · 993 Bytes
/
addPrefixFolder.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
import os
import sys
import tkinter as tk
from tkinter import filedialog
def selectFolder():
folder = filedialog.askdirectory(
title="Selecteer een map waarin de submapen hernoemd moeten worden"
)
if folder:
return folder
def addPrefix(folderPath, prefix, logFile):
with open(logFile, "w") as log:
subfolders = [name for name in os.listdir(
folderPath) if os.path.isdir(os.path.join(folderPath, name))]
for subfolder in subfolders:
oldPath = os.path.join(folderPath, subfolder)
newSubfolder = prefix + subfolder
newPath = os.path.join(folderPath, newSubfolder)
os.rename(oldPath, newPath)
log.write(f"'{subfolder}' hernoemd naar '{newSubfolder}'\n")
if __name__ == "__main__":
folderPath = selectFolder()
prefix = input("Welke prefix moeten de mappen krijgen? ")
logFile = folderPath + "\logfile_add_prefix.log"
addPrefix(folderPath, prefix, logFile)