-1

I am trying to use shutil.copy to copy files that I don’t know the whole name for. The names typically are 11_11_2023_functional. The date changes each for each file but they are in separate folders. How can I copy the file based on the fact that it says ‘functional’ in the name of it?

I was using the basic shutil.copy command and it works. I tried using a variable in the name but it won’t work because I am unaware of the date on the file name.

Will V
  • 1
  • 1
  • 2
    `files = glob.glob("*_functional")` etc. if you're feeling motivated write a regex – Chris_Rands Jul 18 '23 at 20:49
  • Use `glob.glob()` to crawl through directory trees, look for filenames that fit your needs with `os.path`-function you can check, creation time, size, etc. when you have identified the correct file, copy it with`shutil.copy` – destructioneer Jul 18 '23 at 20:53

1 Answers1

0
import glob
import shutil
files = glob.glob("/*/*_functional")
for file in files:
    shutil.copy(...)

/*/ for folder and *_functional for file name.

Eftal Gezer
  • 191
  • 1
  • 8