Directory.GetFiles - Do NOT get temp. files

Hello there

I am currently using this following assign value to show me the 2 most newest files in a directory folder. This folder only contains excel files, and from time to time, there will be a temporary .xlsx file because someone has opened a file in the folder.

How can I work around these temp-files? I dont wanna have to run each file through a loop…

String.Join("", Directory.GetFiles(FolderPath,FileExtension,SearchOption.TopDirectoryOnly).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(2))

Any help is appreciated!

Good day :slight_smile:


Try with the following query, added filter to check the temp file names which will start with some special characters.

String.Join("", Directory.GetFiles(FolderPath,FileExtension,SearchOption.TopDirectoryOnly).Where(Function(f) Not f.Name.StartsWith("~$")).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(2))


Thank you very much - this was just what I was looking for!

However UiPath throws an error when typing this into my workflow.

“Name is not a member of string”

  • f.Name


I changed it to this, and now it is actually working! :slight_smile: Thanks!

String.Join("", Directory.GetFiles("\\XXX","*.xlsx",SearchOption.TopDirectoryOnly).Where(Function(f) Not path.GetFileName(f).StartsWith("~$M")).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(2))
1 Like

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