How to copy files from a directory to another

A little example of how to copy files from a source to a destination:

# copy file

import shutil


filedacopiare = "Ciardi.PNG Merola.PNG Fluri.PNG Romano.PNG Saja_A.PNG".split()
src = "H:\\avatars\\"
dest = "H:\\formazione.github.io\\formazione.github.io\\Programmi20192020\\text_4ce\\"
for f in filedacopiare:
    shutil.copyfile(src + f, dest + f)

Copy all files of a type (png) from a folder to another

This time I can copy all the files in a folder into another, without having to name them.

# copy file

import shutil
from glob import glob

src = "H:\\avatars\\5bs\\"
filedacopiare = glob(src + "*.PNG")
print(filedacopiare)
dest = "H:\\formazione.github.io\\formazione.github.io\\Programmi20192020\\text_5bs\\"
for f in filedacopiare:
    f = f.split("\\")[3]
    print(f)
    shutil.copyfile(src + f, f"{dest}{f}")
    print("copied" + f)

 


Subscribe to the newsletter for updates
Tkinter templates
My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts