Let me explain the scenario.
After completion of certain activities one file should be downloaded . Based on whether the file has been downloaded or not I need to execute further steps.
Even if the file is downloaded, the file name changes in each run.
So, I need to check whether the the required file is downloaded or not. Please suggest some sol.
@siddhi ,
Yes . But the “FileName” is Unique for the one which is latest and the old one isn’t it?
Anyhow to get the Latest file from the downloads folder you can use below method.
Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)+"\Downloads").[Select](Function(x) New FileInfo(x)).Where(Function(f) f.Extension.Equals(".pdf")).OrderByDescending(Function(x) x.LastWriteTime).Take(1).ToArray()(0).ToString
Note : I have asumed the file is PDF .You can change the file extension acordingly.
Hi @siddhi
Try this str_filepath = Directory.GetFiles(yourfolder_path,“*.txt”).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Tolist(0)
@Jithesh_R@lrtetala
Using this method , m getting the file name which is latest.
But in my case sometimes the file is getting downloaded or sometimes not. So your method works in only if the file is downloaded.
but when file is not downloading then also this method retrieves the last downloaded file which is wrong. Bcoz based on whether the file is getting downloaded or not after performing some activities, I need to perform other actions too.
I would say you can use a wait for download activity. https://docs.uipath.com/activities/other/latest/workflow/get-last-downloaded-file
This will wait for a download specified in a specific path, and if the file is downloaded it will proceed.it also depends on how this file is getting inputted into your workflow. Linq queries work good but you can also use a foreach folder activity and configure it to what you need based on the conditions you set in the properties. Then you are able to use a check if file exists activity which outputs a boolean, and based on this condition of the boolean then you can also configure your workflow based on that. let me know if this has helped