最近工作的项目需要用到 python,
好久好久没写过博客了,希望记录下学习python 的历程。
今天写了一个小小的文件转换小程序,把.bat file 转为json文件,
'''
Create 2014/4/28
Be used to transfer bat file to json
author: Sun,Chenhui
'''
import sys,os
def getcurrentpath():
curpath=os.path.dirname(__file__)
print curpath
return curpath
def listcurrentdir(curdir):
for lists in os.listdir(curdir):
path=os.path.join(curdir,lists)
#print path
if os.path.isfile(path):
if path.endswith("bat"):
print path
writeTojs(path)
def writeTojs(batFileName):
import sys, os
contents=open(batFileName).read()
fileToWrite = os.path.splitext(batFileName)[0][0:] + ".js"
output = open(fileToWrite, "w")
output.write(contents)
output.close
print "Successfully to write"+fileToWrite
def main():
listcurrentdir(getcurrentpath())
if __name__ == "__main__":
main()