from os import makedirs from os import listdir from os.path import join from shutil import copy from concurrent.futures import ThreadPoolExecutor NUM_FILES = 5000 # + # copy a file from source to destination def copy_file(src_path, dest_dir): # copy source file to dest file dest_path = copy(src_path, dest_dir) # report progress print(f'.copied {src_path} to {dest_path}') def main(src='../../AVA_src/images/images/', dest='../../AVA_src/images_5k/'): # create the destination directory if needed makedirs(dest, exist_ok=True) # create full paths for all files we wish to copy files = [join(src,name) for name in listdir(src)][:NUM_FILES] print("Files: ",files) # create the thread pool with ThreadPoolExecutor(10) as exe: # submit all copy tasks _ = [exe.submit(copy_file, path, dest) for path in files] if __name__ == '__main__': main()