-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfolders.py
94 lines (81 loc) · 3.01 KB
/
folders.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import os
from io import open
import tkinter as tk
from tkinter import filedialog
from shutil import copy
import random
# from distutils.dir_util import copy_tree
class folders:
def __init__(self):
self.root = ''
self.dest = ''
def selectRoot(self):
root = tk.Tk() # esto se hace solo para eliminar la ventanita de Tkinter
root.withdraw() # ahora se cierra
file_path = filedialog.askdirectory()
self.root = file_path
return self.root+'/'
def selectDestination(self):
root = tk.Tk() # esto se hace solo para eliminar la ventanita de Tkinter
root.withdraw() # ahora se cierra
file_path = filedialog.askdirectory()
self.dest = file_path
self.dest += '/copy/'
os.mkdir(self.dest)
return self.dest
def formarRute(self):
newRute = ''
for char in self.root:
if(char == '\\'):
newRute += '/'
else:
newRute += char
return newRute
def copyElements(self,root_dir,dest_dir):
folderList = []
for file in os.listdir(root_dir):
name,ext = os.path.splitext(root_dir + file)
if ext in ['']:
folderList.append(name)
else:
# falta hacer que modifique los textos
name = name.split('/')
name = name[-1]
copy(root_dir + file, dest_dir + name + '_copy' + ext)
# print(dest_dir + name + '_copy' + ext)
# print('\n')
archive = open(dest_dir + name + '_copy' + ext)
self.getData(archive,dest_dir,name,ext)
for i in range(len(folderList)):
aux = folderList[i].split('/')
aux = aux[-1]
os.mkdir(dest_dir+aux)
self.copyElements(folderList[i]+'/',dest_dir+aux+'/')
def getData(self,file,dest_dir,name,ext):
try:
arc = file.readlines()
lista = []
for line in arc:
for char in line:
if(char.isdigit()):
randuppercase = chr(random.randint(ord('A'), ord('Z')))
char = randuppercase
lista.append(char)
# lista.append(randuppercase)
elif(char.isalpha() and char != ''):
randnum = random.randint(0,15)
char = str(randnum)
lista.append(randnum)
elif(char == '\n'):
lista.append('\n')
else:
lista.append('')
string = ''.join(map(str,lista))
res = open(dest_dir+'aux'+ext, 'w')
res.write(string + '\n')
res.close()
file.close()
os.rename(dest_dir+'aux'+ext,dest_dir+name+'_mod'+ext)
# os.remove(file)
except print(0):
file.close()