Looking For File With A Specific Naming Convention EveryDay

Hello,

I am trying to write UiPath Automation Script to look for a file in specific format and if true send me an email otherwise email me saying file does not exists.

See below as file format, everything it changes with today’s date.

EPICTRAN_20241010124347242.txt
EPICTRAN_20241009112911416.txt
EPICTRAN_20241008104954766.txt
EPICTRAN_20241007133602565.txt

Can you help me as far as how I would write this script and reference file with this specific naming convention. I am hitting error for below:

File Exists: Expression Activity type ‘VisualBasicValue`1’ requires compilation in order to run. Please ensure that the workflow has been compiled.

This is what I have in the File Path:

“\epic-nas.et1157.epichosted.com\xfr\nonprd\toODB\Claims\PBClaims\CRD\TEST1\archive\”+“EPICTRAN_”+Now.ToString(“YYYYMMDD”)+“*.txt”

ensure that " is used for double quotes and not the inverted ones ”

Hello

In addition I would also change your date format from:
YYYYMMDD

To:
yyyyMMdd

Cheers

Steve

Thanks the scripting worked with the changes, however it still could not find the files:

Example of File Names:
EPICTRAN_20241010124347242.txt
EPICTRAN_20241009112911416.txt
EPICTRAN_20241008104954766.txt
EPICTRAN_20241007133602565.txt

“\epic-nas.et1157.epichosted.com\xfr\nonprd\toODB\Claims\PBClaims\CRD\TEST1\archive"+“EPICTRAN_”+Now.ToString(“yyyyMMdd”)+”*.txt"

I am trying to write a script that would send me email if file is found and if not found with this specific format daily then it would email me stating no file exists. I am using If and Else statement.

Thanks the scripting worked with the changes, however it still could not find the files:

Example of File Names:
EPICTRAN_20241010124347242.txt
EPICTRAN_20241009112911416.txt
EPICTRAN_20241008104954766.txt
EPICTRAN_20241007133602565.txt

“\epic-nas.et1157.epichosted.com\xfr\nonprd\toODB\Claims\PBClaims\CRD\TEST1\archive"+“EPICTRAN_”+Now.ToString(“yyyyMMdd”)+”*.txt"

I am trying to write a script that would send me email if file is found and if not found with this specific format daily then it would email me stating no file exists. I am using If and Else statement…

check what is on the filesystem / folder present
today is: 20241011 and from the above list all files are from yesterday

Thanks so I would have still expected to receive an email stating “File Does Not Exists”.

I just tried updating the file name to today’s date and its still not working. For some reason its not finding the file.

1.1 Main Sequence (Sequence)
Private = False
Variables
out_FileExistsX_1__Exists(Boolean)
Activities
1.25 File Exists (FileExistsX)
Path = "\epic-nas.et1157.epichosted.com\xfr\nonprd\toODB\Claims\PBClaims\CRD\TEST1\archive"+"EPICTRAN
"+Now.ToString(“yyyyMMdd”)+“*.txt”
Exists = _out_FileExistsX_1__Exists
Private = False
1.11 If (If)
Condition = _out_FileExistsX_1__Exists
Private = False
Then
1.15 Sequence (Sequence)
Private = False
Activities
1.16 Use Desktop Outlook App (OutlookApplicationCard)
Account mismatch behavior = UseDefaultEmailAccount
Private = False
Body
1.17 Do (Sequence)
Private = False
Activities
1.18 Send Email (SendMailX)
Account = Outlook
To = Nirmit.Kansagra@rwjbh.org
Subject = FILE EXISTS
Save as draft = False
Importance = Normal
Sensitivity = Normal
Max body document size = 2
Body type = Html
HTML body from file
HTML Template = .data/HtmlContent0.html
Private = False
Else
1.14 Sequence (Sequence)
Private = False
1.2 Use Desktop Outlook App (OutlookApplicationCard)
Account mismatch behavior = UseDefaultEmailAccount
Private = False
Body
1.3 Do (Sequence)
Private = False
Activities
1.4 Send Email (SendMailX)
Account = Outlook
To = Nirmit.Kansagra@rwjbh.org
Subject = FILE DOES NOT EXISTS
Save as draft = False
Importance = Normal
Sensitivity = Normal
Max body document size = 2
Body type = Html
HTML body from file
HTML Template = .data/HtmlContent1.html
Private = False

it looks like you are using the file mask within a file exists activity
file exists activity is not supporting a file mask

instead of use the following condition on the if activty only:

System.IO.Directory.GetFiles("\epic-nas.et1157.epichosted.com\xfr\nonprd\toODB\Claims\PBClaims\CRD\TEST1\archive", "EPICTRAN"+Now.ToString("yyyyMMdd")+"*.txt").Any()

and also recheck the parent folder path as we do feel that after archive the \ was missing in your sample, but we assume that the file name starts with EPICTRAN

So I tried with the updates mentioned, however, now I am hitting another error stating Main.xaml: BC30512: Option Strict On disallows implicit conversions from ‘Boolean’ to ‘String’. The selected value is incompatible with the property type.

Below is the updated script:

System.IO.Directory.GetFiles("\epic-nas.et1157.epichosted.com\xfr\nonprd\toODB\Claims\PBClaims\CRD\TEST1\archive"+“EPICTRAN_”+Now.ToString(“yyyyMMdd”)+“*.txt”).Any()

show us where it was modelled e.g. screenshot activity and its settings

Kindly note:

so the file exists activity is obsolete and the statement has to be used as mentioned at the If Activity condition setting

You can directly use this LINQ expression in the condition of the ‘If’ activity:

Directory.GetFiles("\epic-nas.et1157.epichosted.com\xfr\nonprd\toODB\Claims\PBClaims\CRD\TEST1\archive\").Any(Function(file) Path.GetFileName(file.ToString).StartsWith("EPICTRAN_" + Today.ToString("yyyyMMdd")) AndAlso Path.GetExtension(file.ToString).Contains("txt"))

This LINQ retrieves all files in the specified path and checks if any of them start with the desired naming format while ensuring the file extension is .txt. It returns a boolean, making it suitable for use directly in the condition part of the ‘If’ activity.

For example:

Directory.GetFiles([YOUR_FOLDER_PATH]).Any(Function(file) Path.GetFileName(file.ToString).StartsWith([FIXED_PART_OF_THE_NAME]) AndAlso Path.GetExtension(file.ToString).Contains([EXTENSION]))

Here’s a screenshot of a found case:

Not found case:

Finally I got it working, I did not read your earlier post about File Exists being obsolte.

I added this below script under If condition and also changed after archive to archive"," (Previously was using archive"+")

Script:

System.IO.Directory.GetFiles("\epic-nas.et1157.epichosted.com\xfr\nonprd\toODB\Claims\PBClaims\CRD\TEST1\archive",“EPICTRAN_”+Now.ToString(“yyyyMMdd”)+“*.txt”).Any()

1 Like

Perfect, so the topic can be closed by marking the solving post as solution
Forum FAQ - How to mark a post as a solution - News / Tutorials - UiPath Community Forum

This is really awesome thank you so much. This will be very beneficial for another script we need to do.

1 Like

we would keep in mind that there are multiple options to achieve the task. However, we recommend combining techniques to achieve

  • short codes
  • readabillty

An example:

strFolder =

"\epic-nas.et1157.epichosted.com\xfr\nonprd\toODB\Claims\PBClaims\CRD\TEST1\archive\"

Condition:

new System.IO.DirectoryInfo("strFolder ").Getfiles("EPICTRAN_*.txt").Any(Function (x) x.Name.Contains(Now.toString("yyyyMMdd")))

so we can avoid using Path.GetFileName, Path.GetExtension

So it is up to you @nirmit.kansagra on what will better match to your skillsets

Sorry one last question, is there anyway I can configure this script, where once it finds the file, it spits out name of the file and have that emailed to me the name of the file.

I am looking to get alert setup where if file is received by 2pm, have alert go out to me stating CRD file “EPICTRAN_20241010111358930” was received. I want the exact file name to spit out.

Sorry one last question, is there anyway I can configure this script, where once it finds the file, it spits out name of the file and have that emailed to me the name of the file.

I am looking to get alert setup where if file is received by 2pm, have alert go out to me stating CRD file “EPICTRAN_20241010111358930” was received. I want the exact file name to spit out.

we suggest to scope one topic = 1 case
So, other researchers can find the solution for their similar use cases
the origin topic was answered (temporary you closed it also by solution mark)

just close this topic and open a new one for your last question

new System.IO.DirectoryInfo("strFolder ").Getfiles("EPICTRAN_*.txt").Where(Function (x) x.Name.Contains(Now.toString("yyyyMMdd"))).Select(Function (x) x.Name).toArray

for example will a return a string array with all found file names

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.