Searching for the newest excel files and copying them to a new folder

Hi everyone,
I’m new to Ui Path and created my first workflow. But I’m having some problems, I hope you can help me with this.

Here is what the worklfow is supposed to do:

  1. the application must open a folder in which there are a dozen or so more folders.
  2. then a for each loop goes through each folder and searches for the newest xlsx file in each folder. (except 2 of these folders! Searchoption must exclude these: folder1 and folder2)
  3. if it finds a new file, it must take the first 3 letters of the file name. (for example the TRS of TRS_currentfolder_Date.xlsx) and rename it to "Newfolder_TRS.xlsx and move all the files to the new folder (a collective folder).

so far I came across 2 problems:

  1. I don’t really know which static method I should use for the assign action at the beginning of the workflow to search for the newest file in each folder. as of now my workflow can only search for every file in each folder. I tried the method "Directories.GetDirectories(path, “*.xlsx”,SearchOption.AllDirectories).Where(function(s) NOT s.function(“folder1”, “folder2”)) but it doesn’t work, also it can’t search for folders with newest filles. there is another method I know about the “NewDirectoryInfo.Getfiles” method, but it doesn’t work with the rest of the string types. it only works with Directory and Fileinfo types which can’t be converted into string according to Ui path.

  2. At the end of the workflow there is a problem with the assign action: name=filename.Split("_").
    it says “Open strict on doesn’t allow implicit conversions from string to char.”

here is the link to my workflow. PW: Excel
link_// _link

Thanks a lot!

For 2nd problem u can use something like this


Can u plz elaborate your 1st problem?

Cheers @B.D

Hi Abdur Rahman,

I’m basicly searching for a method which does both: searches for the newest file and exludes the search in folder1 and folder2, but not the other folders.

About the other method you mentioned… Do I have to insert my variable instead of “yourStringHere” or is it part of the method ?

Holen Sie sich Outlook für Android

“yourStringHere” refers to your filename from which u will extract 3 letters

get all the files and folders using Directory.GetFileSystemEntries(path, “*.xlsx”, SearchOption.AllDirectories); then loop for each of the file then use if condition activity to check filename and see if u get “folder1” then use continue activity to just skip the loop

How are you going to identify new file is it by date? then sort by date using “OrderByDescending func” or compare with current date

Hope this helps @B.D

1 Like

Abdur Rahman, thank you very much for your help. it’s a nice alternative way of doing it, I never thought about it.

1 Like