How to select a particular file and do some actions

Hi People,

My problem is that, there will be a couple of excel sheets (4-5 at least) created as a result of previous actions.

I want to select particular excel file (based on name) and change the file name, do a couple of action in the excel file and save it.
All the other files simply save it and close.

It is much appreciated if someone can help me to figure out a solution.

Many thanks in advance.

In for each, give
(Directory.getfiles(“Folderpath”,“*.xlsx”))
then in if condition check

item.tostring.contains(“filename”)

1 Like

@muhamed_fasil the files will be created and is will be opened already by a previous process.

The files are not to be saved in the same folder.

Adding to it, the file names are generated based on the creation time and hence it is not same always. Ex: “HEU Wild101122 0845” (Format: ClientnameMMDDYY HHMM)

@Karthikeyan_CS ,
Do you have the path of all the folders?

@Karthikeyan_CS ,
Instead of the hardcorded values you can pass the variables to it
if filename is ClientnameMMDDYY HHMM then check
If item.tostring.contains(“Clientname”+now.date.tostring(“MMddyy”))

Hi @muhamed_fasil - The files are auto created based on previous process (out of our control).

The names of these files are not hardcoded, these are auto generated based on specific format.

3-4 files will be created as the outcome of process 1.

The process 2 is to select specific file based on its name (Ex: if the file name format is ClientnameMMDDYY HHMM, then i should be able to select the excel sheet naming Clientname*) and do couple of actions in the file and save it and close it.

The process 3 is to select another specific file based on its name and save it and close it.

The process 4 is to select another specific file based on its name and save it and close it, this goes on until all the excel files are closed.

Restrictions of the project:
The files are autocreated and it will all be opened in the screen automatically. Screen Attached for reference.

Please advise.

These are only created by the previous process… Saving part is to be handled by UiPath.

Hi @Karthikeyan_CS ,

Are all the Processes (Process 1, 2, 3) that you are referring to are UiPath Processes ?

If they are, then we could also handle saving the files in that Specific Process itself, Instead of making the Other/Next Process do it.

If they are not UiPath Processes, then we can perform saving and closing of all the files at once, Then perform the required operations in the background by Selecting the file using Directory.GetFiles("") method.

For Closing / Saving the file (After Process 1), assuming that it has already been saved atleast once.
Give a try on Killing all the Excel instances using Kill Process Activity.

Then check if the Files exist and is updated as per Process 1. If it exists, we could perform the operations by selecting the Required file from it as mentioned above.

If the files do not get saved when after performing the Kill Process or is not updated as per Process 1, then we would need to introduce either a VBA/Interop approach for saving the Opened files or Switch to UI Operations.

Let us know if you have tried already the approaches mentioned above and provide us it’s results.

After saving the excel in each process, add an Element exists to see if excel is automatically opened after creation. If the file is open then close it so that there are no files opened for next process.

Hi @supermanPunch - I’m running an macro file in process 1, which processes the data and put in separate excel sheets and keeps open in the backgroud.

The bot is expected to select each excel file and save it to desired location and then close it.

The name of one file is constant, other file names are created based on the running date and time.

Screenshot attached for reference.

Hi @pratik.santani - I’m running an macro file in process 1, which processes the data and put in separate excel sheets and keeps open in the background.

The challenge is that, i cannot select each files and save those which are auto created as outcome of process 1.

The bot is expected to select each excel file and save it to desired location and then close it.

The name of one file is constant, other file names are created based on the running date and time.

Screenshot attached for reference.