I'm trying to write a script in databricks that will select a file based on certain characters in the name of the file or just on the datestamp in the file.
For example, the following file looks as follows:
LCMS_MRD_Delta_LoyaltyAccount_1992_2018-12-22 06-07-31
I have created the following code in Databricks:
import datetime
now1 = datetime.datetime.now()
now = now1.strftime("%Y-%m-%d")
Using the above code I tried to select the file using following:
LCMS_MRD_Delta_LoyaltyAccount_1992_%s.csv'% now
However, if you look closely you will notice that there is a space between the datestamp and the timestamp, i.e between 22 and 06
LCMS_MRD_Delta_LoyaltyAccount_1992_2018-12-22 06-07-31
It is because if this space that is preventing my code above from working.
I don't think Databricks supports wildcards so the following won't work:
LCMS_MRD_Delta_LoyaltyAccount_1992_%s.csv'% now
Someone once suggested TRUNCATING the timestamp.
Can someone let me know if:
A.TRUNCATING will solve this problem
B.Is there a way to my code LCMS_MRD_Delta_LoyaltyAccount_1992_%s.csv'% now
To select the whole file? Bearing in mind I definitely need to select based on current date.. I just want to be able to use my code to select on the file.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…