码迷,mamicode.com
首页 > 编程语言 > 详细

python 复制文件到其他路径

时间:2018-11-30 14:04:04      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:rom   erro   etc   line   error   foxmail   path   复制文件   dmi   

#!/usr/bin/env/python
# -*- coding: utf-8 -*-
# @Time    : 2018/11/7 16:34
# @Author  : ChenAdong
# @Email   : aiswell@foxmail.com

import os
import logging
import shutil


logging.basicConfig(level=logging.WARN)


def txt_reader(_path):
	f = open(_path, "r")
	_type = ""
	for line in f.readlines():
		if line.split("|")[0] == "tokentype":
			tem = line.split("|")[1]
			tem = tem.strip()
			# tem = int(tem)
			if tem == "1.0":
				_type = "admin"
			elif tem == "2.0":
				_type = "c"
			elif tem == "3.0":
				_type = "a"
			else:
				logging.warning("%s 未找到tokentype字段" % _path)
	logging.debug("%s %s" % (_path, _type))
	f.close()
	return _path, _type


def move_to(from_dir, to_dir):
	# tem = from_dir.spilt("/")
	# for _file in tem:
	# 	if os.path.isdir(_file):
	# 		pass
	# 	else:
	shutil.copyfile(from_dir, "./%s/%s" % (to_dir, from_dir))


if __name__ == "__main__":
	for i in os.listdir(os.getcwd()):
		try:
			if os.path.isfile(i):
				_path, _type = txt_reader(i)
				# to_dir = "./%s/%s" % (_type, _path)
				move_to(_path, _type)
		except shutil.Error:
			logging.warning("%s 文件被忽略" % _path)

  

python 复制文件到其他路径

标签:rom   erro   etc   line   error   foxmail   path   复制文件   dmi   

原文地址:https://www.cnblogs.com/chenadong/p/10043393.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!