Moving multiple files that share similar name into their own folder

I am trying to move multiple files in one folder than share a similar name, ie the file name all share the characteristic of having the word “tax” in the file name. I just want to move those files to their own folder.

Try this:
Use a For each activity and for each file in Directory.GetFiles(“FolderPath”) – > if file.toString.contains(“tax”) → Move File (give From and To path)

Thank you for that. It is saying it is not finding my from path in the move file tool

@rachrahul2 please see issue I am having above. The file path I am taking it from is the same one in the for each.

You gave the path but forgot to give the file name there :slight_smile:

In the From path add the file name like this - “C:\Users…\Output\” + File.toString
Same thing for To path - “C:\Users.…\What\” + File.toString

@rachrahul2 hmm it is now giving me a new error

Let’s try this.
Write the from and to (file path + file name) in different write line activities before “Move File” activity and see if they are correct.

@rachrahul2 same error. to be clear I wrote two write lines like this


This time you forgot to give file path for “Folder” variable
and can you show the output of write lines ? There is a syntax error somewhere

Hi
You were almost done
—use assign activity like this
arr_filepath = Directory.GetFiles(“yourfolderpath”)

Where arr_files is a variable of type array of string
—now use a FOR EACH activity and mention the arr_filepath as input and change the type argument as string in the property panel of for each loop activity
—inside the loop use IF condition like this
item.ToString.Contains(“Pages”)
If true it will go to THEN Part where we can use MOVE FILE activity and mention the Path property as item.ToString and in the Destination property mention as Path.GetDirectoryName(item.ToString)+”\”+”Pages”+”_”+Path.GetFileNameWithoutExtension(item.ToString)+Path.GetFileExtension(item.ToString)

Cheers @cbohs002

@rachrahul2 here is the output without the move file activity. It is finding the correct files I am asking it to

It is going through with no error and the correct files are coming out as the output, but I no files are moving into the output folder

You have to use one or the other. Use only one for loop, if you are using second for loop then use item.tostring instead of file.tostring.
so, in this one, just mention “item.toString” in from path (remove everything else)
and in the to path, you are missing “\” after Bot test. (add the "" here)

I’m sorry what do you mean I have to use one or the other. As in I should not be adding what @Palaniyappan said to add after what I already had? This is what I currently have
bottest.xaml (10.6 KB)

Hey,
What I meant is use only one for loop either first one or second. Don’t use both.

I attached the corrected workflow for your reference. Add file path for “Destination” variable and it will work.
bottest.xaml (8.2 KB)

1 Like

Hey, this worked! thanks for your help!

2 Likes