python 复制文件到其他路径
Posted ADChen
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 复制文件到其他路径相关的知识,希望对你有一定的参考价值。
#!/usr/bin/env/python # -*- coding: utf-8 -*- # @Time : 2018/11/7 16:34 # @Author : ChenAdong # @Email : [email protected] 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 复制文件到其他路径的主要内容,如果未能解决你的问题,请参考以下文章
未经授权的访问异常 - 在C#中将文件复制到其他目录时访问被拒绝的路径
[Eclipse]如何往eclipse中导入单个python文件,其它类型代码文件也可以参照该方法