递归地将所有文件合并到一个文件夹中
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了递归地将所有文件合并到一个文件夹中相关的知识,希望对你有一定的参考价值。
This file starts at the bottom of the tree and recursively moves all of the files from that tree into another folder. To avoid overwriting files I prepended all of the files with a 9digit number.
import os, shutil def movefiles(): x=0 inputDir=raw_input("please enter the folder where the files are: ") outputDir=raw_input("please enter the destination folder") for root, dirs, files in os.walk(inputDir topdown=False): for name in files: newname="%09d"%x+name x+=1 shutil.move(os.path.join(root, name), os.path.join(outputDir,newname)) for name in dirs: os.rmdir(os.path.join(root, name))
以上是关于递归地将所有文件合并到一个文件夹中的主要内容,如果未能解决你的问题,请参考以下文章