Dynamic email extraction

Hello everybody,

I want to :

  1. List item Get list of files from specific folder
  2. List item Get the file name that contains the text “test” and assign it to variable
  3. List item If the file name is not “test 1234” then rename it to “test 1234”

I get the (1) step and i store the list of files in a string[array] , but what do I have to do after this? :frowning:

1 Like

Do we need to rename all the files as Test 1234. I think this is not correct and i understand your requirements in a different way.

If the files does not contain test 1234 at the filename then we need to change that right

@sarathi125 No, if the file is not “test 1234” then rename it.

In the (3) step i want to check exactly the value of the name to be “test 1234”

How it is possible to have all the files with the same name…

Give some example file names and how you want to change it…

Hi
Hope these steps would help you resolve this
—once after getting the array variable use a FOR EACH activity and pass the above array variable as input and change the type argument as string in the property panel
—inside the loop use a IF condition like this
item.ToString.Contains(“text 1234”)
If true it will go to THEN part and inside that leave it as it is and if false it will go to ELSE part where we can use a ADD TO COLLECTION activity where in the collection property mention as list_files where it is a variable of type system.collections.generic.list(of string) weigh default value as new list(of string) defined in the variable panel
—now next to this for each loop use another FOR EACH activity and mention the input as list_files and change the type argument as string in the property panel
—inside this loop use a MOVE FILE activity and in the path property mention as item.ToString and in the destination property mention as item.ToString(Path.Getfilenamewithoutextension(item.ToString),”test 1234”)

But it will create all file name with same name
Which won’t allow us to create
So for that include a timestamp along with this
Like in the forest for each loop within the then part use a move file activity mention like this
In path property as item.Tostring and in destination property mention as Path. Getfilenamewithoutextension(item.ToString)+”_”+now.ToString(“hh_mm_ss”)+Path.GetFileExtension(item.ToString)

Similarly in the last for each loop also mention like this
item.ToString(Path.Getfilenamewithoutextension(item.ToString),”test 1234”+”_”+Now.ToString(“hh_mm_ss”))

Hope this would help you
Cheers @the.christopoulos

@sarathi125 I have three different files :

test.xlsx
address.xlsx
car.xlsx

I want from the string of array where i get these values to do the below as I mention :

  1. Get the file name that contains the text “test” and assign it to variable
  2. If the file name is not “test 1234” then rename it to “test 1234”

@Palaniyappan How can I use for each since the string[array] has got one row?

That doesn’t matter buddy whether the array has one value or not
For each will iterate the available number of elements in the array
Cheers @the.christopoulos

@Palaniyappan I get the below error:

1 Like

You have to use simple for each not for each row

Kindly try with for each activity for array or list or any kind of collections
For each row is used for iterating through datatable
Cheers @the.christopoulos

Yes my mistake for this.

Ok, Now I am not pretty sure I understand how I rename the file name where it is in the folder.

Could you please give me an example of code? @Palaniyappan