实验室的一段Python脚本,根据用户指定路径来备份文件

来源:互联网 发布:矩阵加一列 秩不变 编辑:程序博客网 时间:2024/05/20 05:11

一段Python脚本,根据用户指定路径来备份文件

代码如下:

#备份当前访问页面def bakCurAccPage(pathName, strHTML):if strHTML is None:print 'Error: Backup function parameter is invalid.'return Falsetm = str(getCurrentFormatTime('curWholeTime'))fileName = tm + '.dat'dataPath = sys.path[0] + '/bak_html/'#处理路径if pathName is not None:new_path = os.path.join(dataPath, pathName)if not os.path.isdir(new_path):os.makedirs(new_path)else:print 'WARN: The bakckup path is exist, abort create.'dataPath = dataPath + pathName + '/'#备份文件dataPath = dataPath + fileNamefd = open(dataPath, 'w')fd.write(strHTML)fd.write('\r\n')fd.close()return True