-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopyResults.py
50 lines (39 loc) · 1.34 KB
/
copyResults.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
# -*- coding: utf-8 -*-
import os
from shutil import copyfile
if os.name == 'nt':
SLASH = '\\'
else:
SLASH = '/'
def writeNewFile(file_path):
path_elements = file_path.split(SLASH)
# print(path_elements)
built_path = path_elements[0] + SLASH
for index in range(1,len(path_elements)-1):
if not os.path.exists(built_path + path_elements[index]):
os.makedirs(built_path + path_elements[index])
built_path += path_elements[index] + SLASH
copyfile('tei'+file_path[file_path.find(SLASH):],file_path)
def traverseFullTree():
rootdir = 'json'
results_folder_name = 'tei'
for root, dirs, files in os.walk(rootdir):
for name in files:
if '.json' in name:
source_file = rootdir+root[4:]+SLASH+name
target_file = results_folder_name+root[4:]+SLASH+name
print(source_file)
print(target_file)
copyfile(source_file,target_file)
# writeNewFile(results_folder_name+root[3:]+SLASH+name,copy=True)
#On Windows, the Command Prompt doesn't know how to display unicode characters, causing it to halt when it encounters non-ASCII characters
def setupByOS():
if os.name == 'nt':
if sys.stdout.encoding != 'cp850':
sys.stdout = codecs.getwriter('cp850')(sys.stdout, 'replace')
if sys.stderr.encoding != 'cp850':
sys.stderr = codecs.getwriter('cp850')(sys.stderr, 'replace')
def main():
setupByOS()
traverseFullTree()
main()