I have a source directory that has several xml files in nested location. I am trying to write a python script to copy files recursively based on a pattern (say *1.2.3.xml) to a target location.
source
├── master.1.2.3.xml
└── directory
└── fileA.1.2.3.xml
├── fileA.1.2.5.xml
├── fileB.1.2.3.xml
Expected outcome:
target
├── master.1.2.3.xml
└── directory
└── fileA.1.2.3.xml
├── fileB.1.2.3.xml
The following script doesn't do the filtering.
from shutil import copytree
def ignored_files(adir,filenames):
return [filename for filename in filenames if not filename.endswith('1.2.3.xml')]
copytree(source, target, ignore=ignored_files)
What am I missing here?