Hey team looking for advice in UiPath workflow i have a folder of pdf where files needed to be paired up based on shared numeric ID in their names once matched i need to look up the sendername from datatable and move both files into that sender specific folder what the best approach to handle the pairing and file transfer reliably???
Firstly, get files and extract the numeric ID
Use “Directory.GetFiles()” in assign activity to pull all PDFs into a list, then extract the ID from each filename with Regex, since filename conventions drift over time.
Secondly, pair files by ID using LINQ GroupBy. This is the cleanest way to do in one Assign with LINQ instead of nested loops.
Finally, for each pair, look up the sender from your DataTable.
I would handle this using a Dictionary based on the numeric ID in the PDF filename.
Get all PDF files using Directory.GetFiles().
Extract the numeric ID from each filename using a Regex.
Group/store the files by ID in a Dictionary(Of String, List(Of String)).
For each ID, check that exactly 2 PDFs exist. This avoids moving incomplete/duplicate pairs.
Use the ID to find the corresponding SenderName in your DataTable.
Create the sender folder if it doesn’t exist.
Move both PDFs to that folder using File.Move().
This is much more reliable than comparing every PDF with every other PDF using nested loops. I would also log IDs where there are not exactly 2 files or where no matching SenderName is found, so those files can be handled separately instead of being moved incorrectly.