I need assistance in looking for a specific file name in a directory and if the file is found, I need to return the file name and be sent to my outlook email.
I was able to figure out how to look for specific file name by using below (This will find any file that starts with EPICTRAN_ … with today’s date, so example, EPICTRAN_20241011101358930). I am expecting a file with similar naming convention daily.
The issue I am having is, how do I get the file name that was found from above script and then return that and send to my outlook email. I dont know how to save the result of the file that is found thats where I am struggling.
Do you think you can share what you mean this? Sorry I am not the best at coding so was hoping if you can share exactly what you mean? Right now I am using If else statement and in IF i am using the condition System.IO.Directory.GetFiles(“\epic-nas.et1157.epichosted.com\xfr\prd\toODB\Claims\PBClaims\CRD\archive”,“EPICTRAN_”+Now.ToString(“yyyyMMdd”)+“*.txt”).Any() is true then send outlook email stating file found, else send email on outlook stating false.
Thank you so much this. How do I send an email if my file is not found? I want to send email for both cases if found or if not found. I got the email to be sent with the file name if file is found, but don’t know how to send email if not found.
You can use an if activity with the condition using the following expression:
System.IO.Directory.GetFiles(“\epic-nas.et1157.epichosted.com\xfr\prd\toODB\Claims\PBClaims\CRD\archive”,“EPICTRAN_”+Now.ToString(“yyyyMMdd”)+“*.txt”).any()
For True, you can store the filepath in a string variable using the expression:
System.IO.Directory.GetFiles(“\epic-nas.et1157.epichosted.com\xfr\prd\toODB\Claims\PBClaims\CRD\archive”,“EPICTRAN_”+Now.ToString(“yyyyMMdd”)+“*.txt”)(0)
In the else block, you may write logic for file not found
you can get the file name with: System.IO.Directory.GetFiles(“\epic-nas.et1157.epichosted.com\xfr\prd\toODB\Claims\PBClaims\CRD\archive”,“EPICTRAN_”+Now.ToString(“yyyyMMdd”)+“*.txt”).First.ToString
by replacing “.Any()” at the last with “.First.ToString”
Just make sure you use this in the then of your If condition as any similar solution will throw exception if the file is not found
Hie @nirmit.kansagra you can pass the send outlook activity in both condition and as per @Anil_G told you if the condition is true attach the file in the then box . and if not in the else section use send outlook activity and write the mail whichever you want to send …