-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirectoriesManager.py
46 lines (42 loc) · 1.6 KB
/
DirectoriesManager.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
import time
import tkinter as tk
from tkinter import filedialog
from clint.textui import puts, colored, indent
import os
class DirectoriesManager():
def loadDirectoriesToClean(self):
self.directories = []
newDirectory = True
while newDirectory:
root = tk.Tk()
root.withdraw()
dirPath = filedialog.askdirectory()
self.directories.append(dirPath)
puts(colored.magenta('New Folder: '+dirPath))
print('')
puts(colored.green('Do you want to add another folder?[Y/N] '), False)
choice = input()
if not (choice == 'Y' or choice == 'y'):
newDirectory = False
def defPattern(self, pattern):
self.pattern = pattern
self.target ={}
def loadDirectoriesTarget(self):
for group in self.pattern:
puts(colored.green('Please tell us where to put '+group+' files'))
time.sleep(1)
root = tk.Tk()
root.withdraw()
dirPath = filedialog.askdirectory()
self.target[group]=dirPath
puts(colored.magenta('Folder target: '+dirPath))
def cleanDirectiories(self):
for dir in self.directories:
dirItems = os.listdir(dir)
for item in dirItems:
path = str(dir+'/'+item)
if os.path.isfile(path):
for group in self.pattern:
if list(filter(path.endswith,self.pattern[group]))!=[]:
os.replace(path, self.target[group]+'/'+item)
break