-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFile_database.py
More file actions
74 lines (50 loc) · 1.66 KB
/
File_database.py
File metadata and controls
74 lines (50 loc) · 1.66 KB
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
"""
Author: Carolina
Date: 02/14/2021
"""
from tkinter import filedialog
import os
import shutil
def open_rawcsv():
wrkdir = filedialog.askdirectory(title='Choose Input Folder')
os.chdir(wrkdir)
files = os.listdir(wrkdir)
files = [x for x in files if x.endswith('_raw.csv')]
return files
def create_database(csvfiles):
outstr = "#Old Filename,New FileName\n"
for file in csvfiles:
print(file)
outstr += f"{file}\n"
output = open("FileName_Directory.csv", 'w')
output.write(outstr)
output.close()
def renamingFiles_fromdatabase(copy=False):
"""
"""
database_file = filedialog.askopenfilename(title='Database files', filetypes=[('CSV File', '.csv')])
print(database_file)
dirname = os.path.dirname(database_file)
os.chdir(dirname)
# print(os.path.dirname(database_file))
# print(os.path.basename(database_file))
with open(database_file, 'r') as batch:
lines = list(batch)
for line in lines:
if line.startswith("#"):
continue
split_ln = line.split(",")
# print(split_ln)
old_name = split_ln[0]
new_name = split_ln[1].strip("\n")
print(f"{old_name}-->{new_name}")
if copy:
shutil.copyfile(old_name, f"{new_name}_raw.csv")
else:
os.rename(old_name, f"{new_name}_raw.csv")
if __name__ == '__main__':
#Creating Databse
# file_Paths = open_rawcsv()
# create_database(file_Paths)
#Read Database
renamingFiles_fromdatabase(copy = True)