How to order my files in a foulder by last modified file

Hi there, i’m with some folders and in each foulder i have some pdf files that i’ll merge in one pdf, i already have a sequence with the foreachs and etc, but idk how to order the files by the last modified to when i do the merge i get the right sequence in the pdf pages. Can someone help me ? Thanks !!

Hi @Gabriel_Gotardo

You have a for each file in folder with a property

or you can do by

Directory.GetFiles(DirectoryPath,"Optionally include filter if needed").OrderBy(Function(d) New FileInfo(d).LatModifiedTime).ToArray

cheers

Hi, thanks for your reply, the (ForEachFileInFolder) works, but the orderby don’t makes effect. I still getting my files in the order they are in my folder (not ordened) :confused:

@Gabriel_Gotardo

did you try the second one?

and also can you confirm may be those are the last modified times for them?

cheers

Yea, i tried the second one, i’ll show how they are in the paste and how they should be.

ps: code is in c#


i enumerated the firsts one, the concept its the same for the rest

There is more than one date on a file - created date and last updated date. Pay careful attention to which you want to order by.

last updated date

Hi @Gabriel_Gotardo,

Hope this works for you it works for me. Use “Send Hotkey” activity like below

thanks,
Rajkumar

That’s not the right way to do this. You don’t do it with UI automation. You do it with methods and activities that directly read the files.

Is that what you selected in the For Each File in Folder? If it didn’t sort properly, make sure you’re on the latest version of UiPath.System.Activities. Or downgrade if you are. Sometimes things might not work right in certain package versions.

Hi, sorry for the late reply, i’ve got very sick. So, i realized that the order its working, what’s happening is that when i put the (join pdf files) activities in the (ForEachFileInFolder) activities he lost the order because, i need to put a array of pdf files and the array dont follow the order of activities, in resume i loss the order there.

@Gabriel_Gotardo , Did you put the “Join PDF Files” activity directly in “For Each File In Folder” activity? I also had a similar task and for that case, I put the PDF file paths into an array first using “For Each File In Folder”. Then I passed that array to “Join PDF Files” .

arr_fileList = arr_fileList.Append(CurrentFile.Name.ToString).ToArray

1pdf
2pdf

1 Like

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