python 复制文件到其他路径

#!/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)

  

转载于:https://www.cnblogs.com/chenadong/p/10043393.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值