-
Notifications
You must be signed in to change notification settings - Fork 6
/
模板.py
42 lines (36 loc) · 1.25 KB
/
模板.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
# encoding:utf-8
# https://github.com/wangandi520/andyspythonscript
# by Andy
# v0.1
from pathlib import Path
import sys
def writefile(fileName, allFileContent):
with open(fileName, mode='w', encoding='UTF-8') as newfile:
newfile.writelines(allFileContent)
def readfile(fileName):
with open(fileName, mode='r', encoding='UTF-8') as newfile:
allFileContent = newfile.readlines()
return allFileContent
def doConvert(fileName):
# readFileContent = readfile(fileName)
# for eachLine in readFileContent:
# print(eachLine)
# newFileName = fileName.parent.joinpath(fileName.stem + '.html')
# if not Path(newFileName).exists():
# writefile(newFileName, ttempFileContent)
def main(inputPath):
fileType = ['.txt']
for aPath in inputPath[1:]:
if Path.is_dir(Path(aPath)):
for eachFile in Path(aPath).glob('**/*'):
if (Path(eachFile).suffix.lower() in fileType):
doConvert(Path(eachFile))
if Path.is_file(Path(aPath)):
if (Path(aPath).suffix.lower() in fileType):
doConvert(Path(aPath))
if __name__ == '__main__':
try:
if len(sys.argv) >= 2:
main(sys.argv)
except IndexError:
pass