How to get the names of folder and sub folders?

Getting the subfolders 2 level down

My current location :\HANSEN\RPA\Document Management

This is how the folder structure looks like
\HANSEN\RPA\Document Management\user 1\folder 1\folder2.…folder n
\HANSEN\RPA\Document Management\user 1\folder 1.1\folder2.…folder n
\HANSEN\RPA\Document Management\user 2
\HANSEN\RPA\Document Management\user 3\folder 1\folder2.…folder n

I just want to get the path till folder 1 if it exists
Output:
\HANSEN\RPA\Document Management\user 1\folder 1
\HANSEN\RPA\Document Management\user 1\folder 1.1
\HANSEN\RPA\Document Management\user 3\folder 1\

Which activity can I use to get the same?

@hansen_Lobo
To get the subfolders two levels down and retrieve the paths up to “folder 1” if it exists in UiPath, you can use the “Directory.GetDirectories” method and the “For Each” activity. Here’s how you can do it:

  1. Drag and drop a “For Each” activity into your UiPath workflow.
  2. Set the “TypeArgument” property of the “For Each” activity to String.
  3. In the “Values” field of the “For Each” activity, enter the following expression:

mathematicaCopy code

Directory.GetDirectories("C:\HANSEN\RPA\Document Management")

Replace the path with your actual root path.

  1. Inside the “For Each” loop, add another “For Each” activity.
  2. Set the “TypeArgument” property of this new “For Each” activity to String.
  3. In the “Values” field, enter the following expression:

mathematicaCopy code

Directory.GetDirectories(item)

This retrieves the subfolders within the current subfolder being iterated.

  1. Inside this nested “For Each” loop, add a “Write Line” activity.
  2. In the “Text” field of the “Write Line” activity, enter the following expression:

mathematicaCopy code

Path.Combine(item, "folder 1")

This combines the current nested subfolder with “folder 1” to form the desired path.

  1. Save and run the workflow to see the output in the Output pane or log files.

Adjust the root path and folder name as necessary, and this UiPath workflow will provide the desired output, printing the paths up to “folder 1” if they exist.

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