How to compare a variable to list folders contained in a folder

Hello All,
i have a list of names saved into a variable and i have one folder which contains number of folders with their names. i want to compare my name variable to the name of the folder contained by the parent folder to see whether wanted folder is present in the parent folder or not. how can i call that folder into my workflow and what could be the if condition.
Thanks in advance!

1 Like

Hi @deepa

LstString=Directory.GetFilesWithout Extension(folder path)
For each item in LstString

if(item.ToString.contains(StrVariable)
Perform the manipulations

Thanks
Ashwin S

1 Like

Hi @AshwinS2
thanks for your reply .i tried this LstString=Directory.GetFilesWithout Extension(folder path) and as a result i am getting files from that target folder but i want folders not files.the target folder contains no. of other folders whose name i want to compare in next step.

2 Likes

Hi @deepa.barode

Check this post

Get folder names

1 Like

Hi @deepa.barode
Kindly follow the below steps that could help you resolve this issue buddy
– out_folder_name = Directory.GetDirectories(“Folder Path”)
where out_folder_name is a variable of type string array
– have all the names saved in a variable of type list(string) or array of string and name it out_name_list
– use a for each loop and mention the out_folder_name as input and change the type argument property of for each loop as string and change the variable in for each loop item as item1
–inside the for each loop, use another for each loop and pass the input as out_name_list and change the type argument as string as well and change the variable item as item2
–in the inner most for each loop use a if condition like this
item1.ToString.Equals(item2.ToString)
–if this condition gets passed it will go to the THEN part of if condition where we need to use any activity we want to carry out…but at last in THEN part use a break activity to avoid comparing even after the match is found
–or it will go to the ELSE part of if condition where we can mention any activity we want

Hope this would help you
Cheers @deepa.barode

did that work buddy @deepa.barode

I used Directory.GetDirectories(“Folder Path”) and got list of folder path. so i think i need to split it and get the names from it.

2 Likes

yes you can get the value by splitting it using SPLIT method

kindly revert for any queries on splitting the string buddy
or did this gets resolved…?
Cheers @deepa.barode

could you tell me how can i save all the splited names into a list variable?
i have created
1.a list variable as List_foldernames
2 .i have splited name into str_foldername
I have assigned “List_foldernames=str_foldername.ToList”
but getting an error.

2 Likes

@deepa.barode

use Add to Collection activity to add splitted values into the list.

1 Like

Fine
you were almost done
–store the split values in a variable of type string array named in_split_values
–create a variable of type list string named in_list and mention the default value for this variable in the variable panel as new list (of string)
–use a for each loop and pass the above variable in_split_values as input and change the type argument as string in the property of for each loop
–inside the loop use a Add to collection activity where mention the property collection with the above variable in_list and item property with value as item, the variable from for each loop
this would add the splitted values to the newly created list in_list

Kindly try this and let know buddy
Cheers @deepa.barode

Thanks for your effort @Palaniyappan
i able to create list without having array variable but still i am not able to get use that list out side the for each loop.

2 Likes

i didnt get you buddy
Can you come again
hope you are talking about the usage of list outside the for each loop, well you can get the value by just mentioning the index value like this
in_list(0).ToString
in_list(1).ToString
in_list(2).ToString
Cheers @deepa.barode

1 Like


so as you can see here i have used the 2nd sequence out side the foreach workflow in this case i am not able to log item1 but if i use it in for each loop then i am able to log all the iteams. and i need to use this list out side the 1st sequence.i hope this is more understandable.

1 Like

Fine @deepa.barode
keep the add to collection here
image
–make sure that the add to collection has collection property with value List_FolderNames and item as stri_FolderName
and mention this in the variable panel and not in the assign activity
image
Then you will be able to get the item value in the log

1 Like

and in the second sequence keep the for each loop alone
Cheers @deepa.barode

1.i tried the same as you said.i need to have that assign activity as well as in variable panel otherwise it shows error.
2. if I change the position of the of activities as you said i will be get the last element of the list not the whole the list

1 Like

can i have a view on your xaml buddy if possible
Cheers @deepa.barode

yes, sure Findpackagesinfolder.xaml (10.4 KB)

2 Likes

well to access the array outside the loop we need to mention the index position, from where the value will be fetched, like this and here i have mentioned the index as 0 and you can mention the index value you want to @deepa.barode