Scenario : I have three files in the folder, with different names ofcourse . I want to iterate through files the folder and move each file to different location based on their names. example, A.xlsx file needs to be moved to x folder , B.xlsx needs to be moved to Y folder, C.xlsx to be moved to Z folder. How do I do that ?
Hi
Welcome back to UiPath forum
Hope these steps would help you resolve this
- We can get the files and it’s path with a assign activity like this
arr_filepath = Directory.GetFiles(“yourfolderpath”)
Where arr_filepath is a variable of type array of string
-
Now use a FOR EACH activity and pass the above array variable as input and change the type argument as string
-
Inside the loop use a SWITCH activity and mention the expression as
Split(item.ToString,”.”)(0).ToString
Inside the switch in each case mention like this
“A”
Which means if A it should move the file to c folder where use a MOVE FILE activity and mention the folder path
Similarly in case2 mention as “B” and use another move file activity and mention the folder path accordingly
This will move the file to each folder we require
Cheers @sujith_naik
Welcome back to our UiPath Community.
Try below expression to get all files from folder.
arrFiles [ ] = Director.GetFiles("FolderPath")
Then use For Each loop to iterate one by one file and inside use Switch case. Based on that it will go to corresponding case and there use Move File activity to move the file to respective folder.