I need help with this Excel Workflow

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
https://workupload.com/file/jtZc8gxf

Thanks a lot!

@B.D

For Getting latest file kindly refer this,

And for the 3 letters, you can use the Substring method which will help you.

Thanks,
Suresh J

1 Like

@sureshj

thank you very mcuh! this looks promissing, exactly what I looked for!

One more question… How can I modify this, so it excludes the file search in folder1 and folder2 ?

String.Join("",Directory.GetFiles("FolderPath","FileType/FIleNameSequence",SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1) )

1 Like

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