Need help with "for each folder in folder" | filter by name

Hello,

I need help with the “For Each Folder in Folder”/ “For Each File in Folder” activities:

I have three folders “aaa1”, “aaa2” and “_aaa3” in the directory c:\temp. In each of the folders there are three files “bbb1”, “bbb2” and “_bbb3”.

With the “for each folder in folder” activity I only want to display the directories without an underscore at the beginning of the directory name and with the “for each file in folder” activity I want to display the files without an underscore at the beginning of the file name. Unfortunately I can’t find a solution how to exclude the names with underscore by “filter by name”.

Does anyone of you know a solution?

Many thanks and best regards
AWAP

Hi @AWAP

Add an if condition and give the condition as

currentfile.tostring.contains(“_”)

In then part just don’t place any activities
In else part place the activities which you wanted to do further.

Regards

Hello @vrdabberu,

i have several thousands of folders and also serveral thousands of files in the folders.

I therefore want to increase the bot’s performance by excluding the files and folders with underlines from the start. The above explanation with three folders and three files was only for ease of explanation.

Thank you and best wishes
AWAP

@AWAP

you can use linq for the same

ListOfFiles = Directory.GetDirectories("FolderPath","*").where(function(x) Not x.Split("/"c).Last.startsWith("_")).ToList

this will give you a list of files in list of string which you can loop using for loop

Similarly for files you can use directory.GetFiles

Edit : Comma with slash in split

cheers

Hello @Anil_G

thank you for your help. I tried you suggestion, but there were the three files (also _aaa3) in the list.

Best wishes
AWAP

Hello @Anil_G,

I replaced the comma in “Split(”,“c)” by backslash. Now it worked. Thank you very much!

Best wishes
AWAP

1 Like

@AWAP

My Bad it should be / only glad it helped

Edited the same above

Close if resolved else happy to help

cheers

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