Sorting issue in workflow uipath

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???

Need Urgent helpp!!
Thank you

Hi @Joskin,

You can try this approach.

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 hope this helps.

Cheers!

Hi, @Joskin

Welcome To UiPath

You can use this approach

Assign statement:-

match = listOfFileNames.FirstOrDefault(Function(fileName) fileName.StartsWith(Path.GetFileNameWithoutExtension(currentFile) & "_"))
sender = dt.AsEnumerable().FirstOrDefault(Function(r) r("FileName").ToString.Equals(Path.GetFileNameWithoutExtension(currentFile)))("Sender").ToString

create Folder Path.Combine(Data\Output",Sender)
Move Both current file and match into the newly created folder.

Welcome :slight_smile:

Ok thank you guys @Prashanth_D and @manish.pal

@Joskin, If this solution works for You, please marks it as the solution to close the topic :slight_smile:

Hi @Joskin

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.