【Python脚本】读取文件、根据读取的数据进行文件拷贝

源代码:

##############################################
# File Name: VipGetPanel.py
# Author:wanglong
# mail:[email protected]
# Created Time: 2019 06.26 18:18:01 
#============================================
# -*- coding: utf-8 -*-
#coding=utf-8
#!/usr/bin/env python
import os
import re
import sys 
import shutil
list = []
Panel_Name = 'PanelParam'
PanelDir = './import-include/platform/panel'	 	
for parent,dirnames,filenames in os.walk('.'):
	for filename in filenames:
		if not os.path.isdir(Panel_Name):	
			os.mkdir(Panel_Name)
			
M_name = open('panelList','r')
for line in M_name:
	Panel_file = str.strip(line)+".h"
	list.append(Panel_file)
num = len(list)

os.chdir(PanelDir)
for i in range(0,num,1):
	for parent,dirnames,filenames in os.walk('.'):
		for filename in filenames:
			if filename == list[i]:
				shutil.copy('./'+str(filename),'../../../'+str(Panel_Name))

代码注释:

1. 获取列表元素个数:

num = len(list)

2.列表添加元素:

list.append(Panel_file)

3.文件拷贝:

shutil.copy('./'+str(filename),'../../../'+str(Panel_Name))
#shutil.copy(新路径,旧路径)

 

你可能感兴趣的:(Python,工作)