Suppose I have a folder that contains a list of files numbered from 1 to 20, and I want to sequentially open each file, one by one, whenever I click the “Run” button. For instance, after pressing the “Run” button once, the first file (File1) should execute, and upon completion, the file should close. Subsequently, on pressing the “Run” button again, the second file should execute and close. How can I achieve this in UiPath?
Welcome to the community
You can store the sequence number to asset or an excel and whenever you run…you can get the number and then increment by 1 and check for the filename with that seuqence number…
Hope this helps
- assign a variable “filePath” to the path of the directory containing the files.
- Use “Directory.GetFiles” activity to retrieve the list of file names in the directory. Store the result in a variable named “filesList”.
- Create a variable named “curIndex” and initialize it to 0.
- Use a “Do While” loop to repeatedly perform the following steps until the “currentIndex” reaches the end of the “filesList”.
- Within the “Do While” loop, use the “Start Process” activity to open the file with the path “filePath + “” + filesList(currentIndex)”.
- Use the “Wait For Exit” activity to wait for the process to complete.
- Use the “Close Application” activity to close the file.
- Increment the “curIndex” by 1.
- Use the “Delay” activity to add a delay between opening each file.
I hope this will resolve your problem.