Retrieving and Matching File Paths

Hello UiPath Community,

I’m currently working on a project where I need to retrieve file paths from a folder and insert them into a specific column named “QR Code” within an Excel sheet. I’m facing a two-fold challenge and would appreciate guidance:

  1. Retrieving File Paths:
  • Is there an activity in UiPath that allows me to retrieve file paths from a specific folder?
  • How can I use this activity to get the path for every file in the folder?
  1. Matching and Inserting Paths into Excel:
  • Once I have the file paths, I want to check if the file name matches any value in the “Customer Name” column of the Excel sheet.
  • If there is a match, I would like to insert the file path into a column named “QR Code” at the corresponding row.
  • Note: It’s possible to have multiple files with the same file name in the folder, so there may be multiple file paths inserted into the “QR Code” column for a single row.

Any insights, suggestions, or sample workflows demonstrating these tasks would be highly valuable. Thank you in advance for your assistance!

Hi,

How about the following sample?

arrFiles = System.IO.Directory.GetFiles(System.IO.Path.Combine(System.Environment.CurrentDirectory,"data"),"*.*",System.IO.SearchOption.AllDirectories)

dict = arrFiles.GroupBy(Function(f) System.IO.Path.GetFileNameWithoutExtension(f)).ToDictionary(Function(g) g.Key,Function(g) String.Join(vblf,g.Select(Function(f) f)))

Then iterate DataTable from the Excel sheet. If there is key which exists in the dictionary, file path is added.

Sample20240128-2.zip (8.5 KB)

Note: If there are multiple filepaths, linebreak is added b/w them. (So it may be necessary to increasing row height if check it)

Regards,

1 Like

Hi @sasadrinksprite

→ Store the Files in a folder in Array of String datatype variable.

- Assign -> Arr_Files = System.IO.Directory.GetFiles("C:\Users\mkankatala\Downloads\Sample Folder")
' Replace your folder path

→ Take an assign activity and create a Int32 datatype variable called Count.

- Assign -> Count = 2

→ Use Read range workbook activity to read the Excel and store in a datatable called Input_dt.
→ Use for each row in datatable activity to iterate the each row in the Input_dt.
→ Inside for each Insert assign activity and create a String variable called QR_Codes.

- Assign -> QR_Codes = String.Join(Environment.NewLine,(From file In Arr_Files
                       Where Path.GetFileName(file.ToString).Contains(CurrentRow("Customer Name").ToString)
                       Select file
                     	).ToList)

→ Take write cell workbook activity to write the QR Codes in the cell. In the Cell Field give like this “C”+Count.toString
→ Take an assign activity to increment the Count Variable.

- Assign -> Count = Count+1

Check the below workflow for better understanding,
2024.xaml (20.1 KB)

Input Excel -
image

Input Folder and Files -

Output -

Hope it helps!!

1 Like

I hope you find the solution for your query. If yes mark my post as solution to close the loop. Else ask your queries here I’m happy to help… @sasadrinksprite

Happy Automation!!

1 Like

Thank you for your reply; it’s effective. However, there’s a specific scenario I’d like to address. In the event that I have multiple files with the same name, I would like these file paths to be inserted under the same name. For example:

image

For these two file paths that share the same name within the ‘CustomerName’ column, I wish to have them added to their respective cell, separated by a comma [,**]. The desired outcome in’QR Code’ Column is as follows: [“C:\Users\Desktop\Mahesh Kankatala.xlsx”, “C:\Users\Desktop\Mahesh Kankatala - Copy.xlsx”] ."

Okay @sasadrinksprite

The above developed workflow work, if one customer name contains multiple files and write those file paths into that corresponding cell. To seperate with comma between multiple file paths, Then change the LinQ expression as below

- Assign -> QR_Codes = String.Join(",",(From file In Arr_Files
                       Where Path.GetFileName(file.ToString).Contains(CurrentRow("Customer Name").ToString)
                       Select file
                     	).ToList)

Hi,

Can you try the following sample?

Sample20240128-2 (2).zip (8.6 KB)

Regards,

1 Like

Check the below Input Customer name have two different files,

Output -

Hope you understand!! @sasadrinksprite

1 Like

Thank you so much for your effort!

It’s my pleasure… @sasadrinksprite

Happy Automation!!

1 Like

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