#/usr/bin/env python
#-*- coding:utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import os
import os.path
def getpwd():
#获取脚本路径
path = sys.path[0]
#判断为脚本文件还是py2exe编译后的文件,如果是脚本文件,则返回的是脚本的目录,如果是py2exe>编译后的文件,则返回的是编译后的文件路径
if os.path.isdir(path):
return path
elif os.path.isfile(path):
return os.path.dirname(path)
def file_get_contents(filename):
if not filename:
print '==== ' + filename + ' is Null! ===='
return 0
if not os.path.exists(filename):
print '====' + filename + ' is not exist! ===='
return 0
f = open(filename, 'r')
text = f.read()
f.close()
return text
def file_put_contents(filename, contents):
if not filename:
print '==== ' + filename + ' is Null! ===='
return 0
dirname = os.path.dirname(filename)
if dirname and not os.path.exists(dirname):
os.makedirs(dirname, 0777)
f = open(filename, 'w+')
f.write(contents)
f.close()
return 1
def scandir(dirname, mod = ''):
if not filename:
print '==== ' + filename + ' is Null! ===='
return 0
if not os.path.exists(filename):
print '====' + filename + ' is not exist! ===='
return 0
if os.path.isfile(dirname):
dirname = os.path.dirname(dirname)
dirinfo = {'parent': '', 'dirs': '', 'files': ''}
for parent,dirs,files in os.walk(dirname):
dirinfo['parent'] = parent
dirinfo['dirs'] = dirs
dirinfo['files'] = files
if mod == 'dir':
del dirinfo['files']
return dirinfo
if mod == 'file':
del dirinfo['dirs']
return dirinfo
return dirinfo
#============= Add Date 2013-12-17 14:00 ======================
更新页面: