Extract file names and write these name in data table #Uipath

Hi,

I have a folder with 12 files that look like this
abcd@202201.xlsx
abcd@202202.xlsx
abcd@202203.xlsx
abcd@202204.xlsx
abcd@202205.xlsx
abcd@202206.xlsx
abcd@202207.xlsx
abcd@202208.xlsx
abcd@202209.xlsx
abcd@2022010.xlsx
abcd@2022011.xlsx
abcd@2022012.xlsx

Also, I’ve already got a data table(dt_names) that looks like the following
Names
Aaron
Andrew
Justin

How do I extract the date of the 12 files and write it into each column of my existing data table, so it would look like this?
Names 202201 202202 202203 … 202212
Aaron
Andrew
Justin

Hi @Andrew1213, welcome to the Community.

  1. Use Assign activity & get the file names in an array:
    fileNamesArray = Directory.GetFiles(“Folder Path in which 12 files are located”)

  2. Iterate through each array element by using ForEach activity.

  3. Inside the loop, use the regex to extract the numeric values & store it in a string variable:
    currentMatch = System.Text.RegularExpressions.Regex.Matches(inputString, pattern)

  4. Inside the loop, after the above action, use Add Data Column to add the columns. In each iteration, the column will be added.

Hope this helps,
Best Regards.

Hi Arjun!

Thank you for your reply!

May I know more about step3. as it keeps showing these two errors

  1. Option Strict On disallows implicit conversions from ‘Integer’ to ‘String’
  2. Option Strict On disallows implicit conversions from ‘Integer’ to ‘RegexOptions’

*for the fileNamesArray in step 1, I’ve set the variable type to “system.string

Hi,

How about the following sample?

 System.IO.path.GetFileNameWithoutExtension(currentItem).Split({"@"c}).Last

Sample20230322-5L.zip (65.7 KB)

Regards,

1 Like

It works perfectly! Thank you so much

1 Like

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