Want to delete all folder that share a name within subfolders

I cannot figure out how to get UI Path Studiox to search for all folders with name “y”, and then delete them. my main issue is that the name of the folder to be deleted (“y”) changes from day to day, so it needs to be dynamic.

e.g. my folder structure is:

-Colours

  • Yellow
    –Hue
    –Saturation
    –Brightness
  • Blue
    —Hue
    —Saturation
    —Brightness
  • Green
    —Hue
    —Saturation
    —Brightness

I would like to delete all subfolders named “Brightness” within the “Colours” folder.

So far I have used the For Each Folder in Folder and Delete, but can only get it to delete one folder if I give it that exact folder’s path.

Hi @KMan ,
You can check folder name
If them contain “Brightness”, delete
folder name as String, check String is simple
Regards,
LNV

@KMan

  1. Get Folders (Source Folder: Path to “Colours” folder) - Output: foldersList

  2. For Each (item in foldersList)
    3. If (item.Contains(“Brightness”))
    4. Delete Folder (Folder Path: item)

or if you want to extract the files from the directory give

Directory.GetDirectories(“C:\Your\Directory\Path”)

@KMan .
You can add the subfoldernames into an array or list
And then use a for each folder in folder activity *Check the subfolder option)

Inside that Drop an if activity and in condition compare the (Currentfolder.Name.equals(YourArray(index))

Hope it helps you!

Use for each “folder in folder” and check a condition if file.name is “Brightness” then use delete file

Regards,

Hi @KMan ,

You can use the below logic:

 // this will give you all the directories in the root folder including the sub-directories
 foreach folder in  Directory.GetDirectories(rootFolder, "*" , SearchOption.AllDirectories)  
 if Path.GetDirectoryName(folder).equals(yourKeyword) // you can also use contains 
     delete folder