Check filename contains a certain specific naming convention

Program needs to check if a filename contains a specific naming convention - the convention is an underscore followed by a string, comma, and dash with four digits followed by another underscore. This is all with no spaces. For example _ string,string-000 _ How can this be done? The idea is to iterate through filenames in a folder; if a filename does not contain the naming convention then skip to the next iteration i.e. the next file in the folder.

@path1
You can use a For Each with Directory.GetFiles to loop through all of the files in a given directory. The Is Match activity can be used to check each filename against a regular expression. You can use the UiPath regex builder or a tool like regex101 to craft the expression based on your filename conventions.

Hi @path1,

  1. Take for each activity
    for each item in Directory.getfiles(“folderpath”) —> type argument (String)

  2. Take assign activity inside for each,
    fileName (String) = Path.GetfFilename(item)
    By this you’ll get the filename.

  3. Take If activity with the condition as below

System.Text.RegularExpressions.Regex.IsMatch(fileName,"_\w*,\w*-\d{4}_")

Use then & else section of if activity for further process.

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