Write a python function to find all files with a given pattern in a source directory to a different destination directory


Topic: Write a python function to find all files with a given pattern in a source directory to a different destination directory

Solution

import glob
import os
def find_move_files(src_dir_path, dst_dir_path, file_pattern):
    if(os.path.exists(dst_dir_path) == False):
        print("Destination Path doesn't exist")
        return
    all_png_files = glob.glob(src_dir_path+"/*"+file_pattern)
    if (len(all_png_files) > 0):
        for file_name in all_png_files:
            base_file_name=os.path.basename(file_name)
            os.replace(file_name, os.path.join(dst_dir_path, base_file_name))
        return 
    else:
        print("No files with matching pattern found")
        return



List all Python Programs