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
|
#!/usr/bin/python
import
os,sys
def
convert( filename, in_enc
=
"GBK"
, out_enc
=
"UTF8"
):
try
:
print
"convert "
+
filename,
content
=
open
(filename).read()
new_content
=
content.decode(in_enc).encode(out_enc)
open
(filename,
'w'
).write(new_content)
print
" done"
except
:
print
" error"
def
explore(
dir
):
for
root, dirs, files
in
os.walk(
dir
):
for
file
in
files:
path
=
os.path.join(root,
file
)
convert(path)
def
main():
for
path
in
sys.argv[
1
:]:
if
os.path.isfile(path):
convert(path)
elif
os.path.isdir(path):
explore(path)
if
__name__
=
=
"__main__"
:
main()
|
本文转自 linuxpp 51CTO博客,原文链接:http://blog.51cto.com/1439337369/1934061,如需转载请自行联系原作者