Moving Documents out of multiple folder locations

Hi everyone,

Just to let you know I’m somewhat new to UI path. I’m in a little pickle about how to move documents. So I have multiple folders (California, Maine, North Dakota) each folder has an excel doc in it, and that is all I need. I need to move each of those excel docs to one folder. (note I only have 3 rn, but the goal is eventually to do this for all 50 states, so eventually 50 folders lol)

I had a thought to use ForEach, but i couldnt really wrap my head around it. Any suggestions?

Appreciate it.

Hi @Bumi welcome to forum

Try this way

  1. First put all folder inside another main folder

  2. Then use the assign activity

folder_list = Directory.GetDirectories(mainfolder) this will retrive all folder list path in the main folder

Then use for each loop to loop through all folder inside the main folder

(for each folder inside folder_list)

Then use the assign activity

file_list = Directory.GetFiles(folder)

Inside the the for each loop use another for each loop to loop through all files in the subfolder
(for each file in file_list)

Inside the second for each loop use the move file activity to move the file to another folder

With filepath to moved (which is file which we are iterating) and destination folder where the file to be moved are to be provided as input in the move file activity

Hope this explanation helps you

Mark it as solution if it helps to answer your query


Nived N :robot:

Happy Automation :relaxed::relaxed::relaxed::relaxed:

1 Like


I really appreciate the quick response. I’ve put the folders into one folder, thats what the DataFolder variable is for.

Having a lil trouble understanding the 2nd assign:
file_list = Directory.GetFile(folder) what is the “folder” variable?

I understand the move part and everything else … i think

Gross, srry I have no idea y it put the pic right in the middle.

Hi @Bumi in case it is item

Because u are iterating through each item in folder_list

Each item is a folder path of subfolder which we are iterating

Since u are using another for each inside the for each so instead of item name it as folder

So it looks like for each folder in folder_list

1 Like

Thank you @NIVED_NAMBIAR suuuuuppper helpful. Also I’m sorry I’m bothering u so much but I feel like I’m so close to being done and I can call it a night. My assign of:
file_list = Directory.GetFile(folder) is returning an error that says “Option Strict On disallows implicit conversions from Object to String”

Both my folder_list and my file_list are an array of strings, isn’t this the correct data type?

Thank you so much for the help, and sorry for bothering u again.

Hi @Bumi

The reason of validation error is Because

In Directory.GetFiles(folder)

folder actually means the folder path which should be in string format

But when u use for each activitiy defaulty it argument type is being set as Object (which implies each file which we are iterating is object not of string type ) so in order to do this

You should change the argument type in for each property panel as String instead of object.

Hope it helps you


Nived N :robot:

Happy Automation :relaxed::relaxed: :relaxed:

EUREKA!! It runs like a champ. You the best @NIVED_NAMBIAR. tanks a million :slight_smile:

1 Like

My pleasure @Bumi

Keep learning and explore more :blush:

Happy Automation :relaxed::relaxed::relaxed:

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