#! Python3
# -*- coding utf-8 -*-
'''
copy specific file from srcpath to destpath
'''
import os
import shutil
def CopyFileToDest(sourcepath,fileclass,destpath):
#Traverse the source folder
for filename in os.listdir(sourcepath):
# Gets the absolute path to the file and folder names
filepath = os.path.join(filename)
# Determine if it is a folder
if os.path.isdir(filepath):
# If the folder calls the function again
CopyFileToDest(sourcepath,fileclass,destpath)
# Determin if it is file
elif os.path.isfile(filepath):
# if the file class is specific class
if filepath.endswith(fileclass):
shutil.copy(filepath,destpath)
# fun call
SendFileToDest('d:\\src','.txt','d:\\dest')
【小工具】Python实现特定类型文件的移动
最新推荐文章于 2024-07-12 19:06:42 发布