这个用不着python吧,
在windows下直接 Xcopy B A /s /e /y
在linux下 cp -r A B
但是还是给你提供python的方法吧
#!/usr/bin/env python# -*- coding: utf-8 -*-
"""
# ------------------------------------------------------------------------
# FileName: [file_dir_copy.py]
# Purpose: [copy dir B to A]
# ------------------------------------------------------------------------
"""
# import necessary module
import os
import shutil
from os.path import walk
oj = os.path.join
oif = os.path.isfile
oid = os.path.isdir
PathA = "D:\\PathA\\"
PathB = "D:\\PathB\\"
# ============================================================
def copy(arg, dirname, filenames):
"""
Purpose / Usage: copy() is a func to create dir and copy file
from PathB to PathA by recursion
Parameter(s):@arg, @dirname, @filenames
"""
# for showing progress
print dirname
# remove root dir
diretory = dirname.replace(PathB, "")
dirnameA = os.path.join(PathA, diretory)
if oid(dirnameA):
# if there is a dir in PathA then check
# if subdirs and files are existing.
for FILE in filenames:
if oif(oj(dirname, FILE)) and not oif(oj(dirnameA, FILE)):
# if not exists files then copy files to pathA
shutil.copy2(oj(dirname, FILE), oj(dirnameA, FILE))
elif oid(oj(dirname, FILE)) and not oid(oj(dirnameA, FILE)):
# if not exsits dir then make dir in PathA
os.system("mkdir %s" % (oj(dirnameA, FILE)))
else:
# if there is no same dir, then create the dir in PatchA,
# and copy files
os.system("mkdir %s" % (dirnameA))
for FILE in filenames:
shutil.copy2(oj(dirname, FILE), oj(dirnameA, FILE))
# shutil.copy2 func can copy with original date
# and time of file.
# ============================================================
if __name__ == "__main__":
walk(PathB, copy, ())
# call copy func recursively
listdir不是进入而是相当于终端命令ls。。read_files=glob.glob('/Users/apple/Desktop/SMJ/
*.txt')
就可以了。
把所有的这些txt文件放到一个文件夹里
打开cmd, 进入到这个放了多个txt的文件夹, 运行命令copy *.txt all.txt
在该文件夹下创建一个python脚本 1.py, 将下列代码复制进去
# coding=utf-8# using python27
file_path = 'all.txt'
with open(file_path, 'r') as f:
card_informations = map(lambda x: x.strip().split('\t'), f.readlines())
for i in range(len(card_informations)):
number = card_informations[i][0]
if len(number)<10:
card_informations[i][0] += '0' # 给小于十位的加上0
# 剔除重复数据
result = []
for i in card_informatios:
if i not in result:
result.append(i)
# 写入新文件
with open('result.txt', 'w+') as f:
for i in range(len(result)):
f.write(result[i][0]+'\t'+result[i][1]+'\n)
4. 运行该脚本, 然后该文件夹下就会多出一个result.txt的文件, 里面放的就是去重完之后的所有卡信息.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)