Hi there,
Trying to get the latest file with this function:
System.IO.Directory.GetFiles(path).OrderByDescending(Function(d) New FileInfo(d).CreationTime).First
But it seems function and new are not recognized:

Can anyone give me a hand, pls?
Note: My project is in C#.
Thanks !!!
Learner007
(Uipath Learner)
2
Hi @javierdavidh Can you try below code once.
Directory.GetFiles(Folderpath).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Tolist(0)
Learner007
(Uipath Learner)
3
@javierdavidh for your reference
Folder path (Files path) - String
Latestfile - String
Thanks! I didi it but still getting same error:
It’s like the reserved commands (Function and New) are not recognized…
Learner007
(Uipath Learner)
5
Hi @javierdavidh can you please try to paste exact code which i have sent to you.
Take assign activity and try the code which i have sent
Remove system.io in the beginning
Hi,
Directory.GetFiles(Filepath).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Tolist(0)
Same error:
Tks!
Learner007
(Uipath Learner)
7
@javierdavidh Can i know which activity you are using to execute that code
ppr
(Peter Preuss)
9
C# Syntax:
Directory.GetFiles("path").OrderByDescending(d => new FileInfo(d).CreationTime).First();
add System.IO to the imports
Learner007
(Uipath Learner)
10
Learner007
(Uipath Learner)
11
@javierdavidh If same code is not working in your system means check for missing Namespaces and Packages - update them
RajKumar_DC
(RajKumar Durai)
12
Hi @javierdavidh,
What about below
Workflow
Xaml
Sequence9.xaml (3.5 KB)
Directory.GetFiles(stPath).OrderByDescending(Function(d) New FileInfo(d).LastModifiedDate).Tolist(0)
Note: Dont use “CreationTime” it will take value base on Time so use “LastModifiedDate”
Thanks,
Rajkumar
RajKumar_DC
(RajKumar Durai)
14
For your kind information
@Learner007 Thanks for all your help !! It was a syntax issue, cause I am using C#, all your samples were in VB.
Thanks !
system
(system)
Closed
17
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.