• 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)
    

      

  • 相关阅读:
    2014/4/9-最近所想
    DNS坑爹呢?!
    c#委托使用
    sqlserver 获取一个月有多少天
    定时提醒模型
    sqlserver导入dbf文件
    json对象中根据主键判断是否有重复数据
    差异备份与恢复
    html编码和解码
    opendatasource问题
  • 原文地址:https://www.cnblogs.com/chenadong/p/10043393.html
Copyright © 2020-2023  润新知