Reputation: 15
I am very new to Python. I want to copy set of files from one folder to another based on the name and not based on data types. So I have a source folder with files like Hello.txt, Hello.dat, Hello.pdf, World.txt, World.dat, Word.pdf. Now I just want to copy files beginning with "Hello" into another folder. I tried many ways but all seems to be based on data type.
Upvotes: 1
Views: 3755
Reputation: 82755
import os
import shutil
files = os.listdir("Path")
for file in files:
if file.startswith("Hello"):
shutil.copy("Full path to file", "Full path to dest folder")
Upvotes: 2