I am trying to assign a dynamic path excel to my variable source_path.
However I dont know what the date of the file will be. it could be anything.. is there a way to just search my drive and look for just "weekly time report" and ignore the date? and read that file to source path?
from pathlib import Path # to work with file paths
import pandas as pd
import pathlib
import re
import os
import shutil
source_path = Path(r'...desktop...path\weekly time report 6.19.23.xslx')
dest_path = Path(r'networkdrive\weekly time report 6.19.23')
shutil.copyfile(source_path ,dest_path )
>Solution :
You can use glob to find the file, then move it with the same name
source_path = next(Path(r'...desktop...path').glob("weekly time report *.xslx"))
dest_path = Path(r'networkdrive', source_path.name)
The Path.glob returns an iterator, use next to get the first one