-
Notifications
You must be signed in to change notification settings - Fork 5
/
autoPinyinVariant2LexiconPronunciation.py
47 lines (45 loc) · 2.09 KB
/
autoPinyinVariant2LexiconPronunciation.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
# coding=utf-8
import sys
import re
import os
# original directory
directory = './PYVLs/'
intermediate_directory = './PYVs/'
# objective directory
destination_directory = './PYPLs/'
intermediate_destination_directory = './PYPs/'
# backup directory
backup_directory = './Backup/'
if os.path.exists(directory):
print('Loading...')
# rescutive
for file_or_folder in os.listdir(directory):
# generate full file path which to be treated
file_path = os.path.join(directory, file_or_folder)
# generate full file path which to save the new file generated.
name_extension = str(file_or_folder).split('.')
name = str(name_extension[0])
destination_file_path = os.path.join(destination_directory, name + '.pyp')
intermediate_file_path = os.path.join(intermediate_destination_directory, name + '.pyp')
# judge wheather one object in the directory is a file.
if os.path.isfile(file_path):
# copy source file to intermediate_directory PYSs
os.system("cp " + file_path + " " + intermediate_directory)
# execute statement.
os.system("python pinyinVariant2Pronunciation.py " + file_or_folder)
# execute backcup and clean operations
# copy source file to backup directory
os.system("cp " + file_path + " " + backup_directory + directory)
# move result to destination directory
os.system("mv " + intermediate_file_path + " " + destination_directory)
# copy result to backup directory
os.system("cp " + destination_file_path +" " + backup_directory + destination_directory)
# delete source file from original directory
os.system("rm " + file_path)
os.system("rm " + os.path.join(intermediate_directory, file_or_folder))
else:
print('Wrong path!')
print('---------------------------------------')
print('Executing ...\n')
print('Congratuation, all the files in directory <PYVLs> have been transformed into ' + destination_directory +' directory.')
print('---------------------------------------')