Move Files to specific folder

How to move files to specific folder with a sorrounding text.

Let’s say if there is a file wherein there’s a word in the filename called “ANSWER”.
Then the file will move to the specific folder.

Example:

FROM:
C:\Users\Demo\Desktop\Delaware\Need_Sorting\Answer-Community.pptx

TO:
C:\Users\Demo\Desktop\Delaware\Sorted\Answer\

1 Like

Hi @prititit

U can try this way

First get all file path in the directory using below assign activity

file_list = Directory.GetFiles(folderpath)

Now use for each loop to loop through each path in file_list (for each item in file_list)

In the for each activitiy use the if condition with condition as

Path.GetFilename( item).ToLower.Contains(“answer”)

If the condition is true then in Then section use move file activitiy to move the file to specific folder

For eg in move file activitiy u can specify like this (item is the filepath)

FROM:
item

TO:
C:\Users\Demo\Desktop\Delaware\Sorted\Answer\Path.GetFileName(item)

Hope it helps

Regards

Nived N

1 Like

Hello @NIVED_NAMBIAR ,

It worked! Thanks!

Another question @NIVED_NAMBIAR.

Is it possible that i can base the specific path in excel.

For example if there’s a word “Abate”, if the action is “NO” then it will go to the “NO” Folder also. But if it is in “Collect” action, then it will go to the “Motion” folder.

See image.

Hi @prititit

Can u explain ur query well
I don’t understand it

Hello @NIVED_NAMBIAR

For example in Column A, there’s a word “Abate” in the filename.

But the action(Column B) of “Abate” is NO. Which means, i will move it to Exclude folder.
But if the Column A is “Additur” and the action(Column B) is “Collect”, then it will move to the “Motion” folder which is from the Column C.

Column B

NO - move to Exclude Folder
Collect - move the file depending on the Category(Column C)

image

Hi @prititit

It is also possible

Do the following

Read the excel file and store in dt1

  1. Assign as below

file_list = Directory.GetFiles(folderpath)

Loop through each files using for each activitiy.

Inside the loop do the following

assign as below

index = (For row in dt1.Rows

Where item.Contains(row(“Document Title”))

Select dt1.Rows.IndexOf(row))

Now use switch condition with condition as

dt1.Rows(index)(1).ToString

Now different case values:

case1: when dt1.Rows(index)(1).ToString equals No, then use the move file activitiy to move the file to the No folder as follows

From : item

To : "D"+Path.GetFileName(item)

case2: when dt1.Rows(index)(1).ToString equals Collect, then use the move file activitiy to move the file to the No folder as follows

From : item

To : dt1.Rows(index)(1)+""+Path.GetFileName(item)

Regards

Nived N :robot:

Happy Automation :relaxed::relaxed::relaxed:

1 Like

thank you so much @NIVED_NAMBIAR! :slight_smile: :grinning:

1 Like

Hello Again @NIVED_NAMBIAR -

I tried your steps. But there’s always an error “Switch: There is no row at position -1”

Guideline.xlsx (9.7 KB) MoveFiles.xaml (8.4 KB)

Hi buddy can u share the screenshot of where u are getting error?

It’s in here, @NIVED_NAMBIAR

Hi @prititit

Sorry I had made some mistake in the solution

Please check the updated solution

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