Still new to python so please dont mind the noob question.I have spend some time first researching and trying to figure it out.I have a files that are in directories.The files look like this;
A_1_BB_Z.txt
A_2_CC_Z.txt
A_4_DD_Z.txt
In my example I would want to get only the first file and I am trying to find and copy this file. The BB,CC is a serial number that is random so I cannot add it to my search pattern and would like to instead use a wild card.If i use the A_1*_Z.txt to search manually on the folder, I can find the file.
I was trying to use shutil to do this and this works only for a complete absolute path. I tried to use a wildcard like this but it couldn't work as I believe shutil requires the absolute path
TargetFolder = r'C:\ELK\LOGS\ATH\DEST'
for row in df.itertuples():
search2 = row.Search2
try:
shutil.copy2(search2, TargetFolder)
except Exception as e:
print(e)
An example of the value of search2 is below;
C:\folder1\Folder2\DL\A_1*_Z.txt
An absolute path like this works but this cannot be implemented because we cant know the BB string
C:\folder1\Folder2\DL\A_1_BB_Z.txt
Any ideas or suggestions on how to best approach this problem