'How to use Python Regular Expressions so that my program only loads in files that have 'formatted' in the title?
I am trying to use python to load in certain excel files that have 'formatted' in the title. I am attempting to use Python regular expressions to do this; however I believe I am not setting up the pattern right. How can I set up a pattern that will only load in titles with 'formatted' in them? Here is a snippet of my code:
cwd = 'C:\\Users\\foo\\Documents\\WDR_Automation\\*.xlsx'
outputs = glob.glob(cwd)
for file in outputs:
name_file = file
print(name_file)
pattern = re.compile(r'(.)|(Formatted$)')
match = pattern.match(name_file)
if match:
print(match)
dest = f'C:\\Users\\foo\\Documents\\WDR_Automation\\Formatted Outputs'
os.replace(file,dest)
print('file exported successfully')
else:
print('no match')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|