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\
@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:
Drag and drop a “For Each” activity into your UiPath workflow.
Set the “TypeArgument” property of the “For Each” activity to String.
In the “Values” field of the “For Each” activity, enter the following expression:
Inside the “For Each” loop, add another “For Each” activity.
Set the “TypeArgument” property of this new “For Each” activity to String.
In the “Values” field, enter the following expression:
mathematicaCopy code
Directory.GetDirectories(item)
This retrieves the subfolders within the current subfolder being iterated.
Inside this nested “For Each” loop, add a “Write Line” activity.
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.
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.