'Find yaml and yml files using glob.glob()
I'm struggling with finding yaml and yml files. What I want is to print two lists of files and check if there is any extra file. I can't figure out what is the regex of glob.glob
I did:
glob.glob('/data/config/**y*ml', recursive=True)))
But it's finding also xml files.
What I have right now is:
ymlFilenamesListA = sorted(map(os.path.basename, glob.glob('/data/config/**{yml,yaml}', recursive=True)))
ymlFilenamesListB = sorted(map(os.path.basename, glob.glob('/app/config/**{yml,yaml}', recursive=True)))
print(ymlFilenamesListA)
print(ymlFilenamesListB)
def compareList(l1,l2):
l1.sort()
l2.sort()
if(l1==l2):
return "No new files"
else:
print("Found new files: ")
print(list(set(l1) - set(l2)))
return sys.exit(1)
print(compareList(ymlFilenamesListA,ymlFilenamesListB))
And my output is:
./find.py
[]
[]
No new files
How can I compare two trees of files and check if there is any missing or some extra?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
