Extract Folder Names inside a Folder and paste the name into an Excel as like a List

Hi I am fairly new with UiPath and trying to create a process where it can extract the folder names within a folder and paste into Excel as a list. I been trying with the “For each folder in folder” function and not sure what to do after that.

I just need the folder names to be copy and pasted essentially, I do not need the files names inside the folders.

if you need the full path of the folder: then you should use

currentFolder.FullName

if you only need the folder name: then you should use

currentFolder.Name
Here’s the screenshot of workflow:

Attaching the workflow below:
In the workflow the datatype of ListFolders is System.Collections.Generic.IEnumerable<System.String>

ListCreation.xaml (6.7 KB)

Thanks and Happy Automation!

Please mark as solution if this works.

Thank you but after getting the list of folder names , how can I get the list into Excel?

Hi @christian.wilsoncartagena ,

Then you don’t need them in a list,
Build a DataTable with one column name FolderName
Use a Add Data Row Activity and add this in a DT.

And use write range to get it all in excel.

Thanks

Happy Automation

Hi @christian.wilsoncartagena

To extract folder names within a folder and paste them into an Excel list using UiPath, you can follow these steps:

  1. Use the “Assign” activity to create a variable to store the folder names. Let’s call it folderList and initialize it as an empty list or an empty array of strings.
  2. Use the “For Each” activity to iterate through each folder within the main folder.
  • Set the TypeArgument of the “For Each” activity to System.IO.DirectoryInfo.
  • In the “Properties” section of the activity, set the Directory property to the path of the main folder.
  1. Inside the loop, use the “Add to Collection” activity to add the name of each folder to the folderList variable.
  • Set the Collection property to folderList.
  • Set the Item property to folder.Name.
  1. After the loop, use the “Write Range” activity to write the folder names to an Excel file.
  • Set the DataTable property to folderList.ToArray().CopyToDataTable().
  • Specify the range where you want to paste the data.

Thanks!!

Hi @christian.wilsoncartagena - Please check the attached workflow

SampleWorkflow.zip (11.1 KB)

Output

Picture1

there is an error, the workflow does not show in UiPath. Invalid document

can you provide a workflow example?

can you show how?

Hi @christian.wilsoncartagena

You can see the workflow below and the file generated through it
WriteFoldersinDT.xaml (9.0 KB)
Folders.xlsx (8.0 KB)

I have added FolderName and FolderPath, 2 columns in Excel.

Thanks

Thank you, this has worked.

Is there a way to seperate the numbers from the text…

Example: My folders contain both text and numbers.

RPA GGG 123 I want just : 123

678 HGA I want just 678

1 Like

Hi @christian.wilsoncartagena

If that worked can you mark the post as solution.
and to the part where you need only Numbers from your folder name’
Use something like this:
Regex.Match(“RPA GGG 123”,“\d+”).Value
image
It will give you only digits.

Thanks

Happy Automation! :slight_smile:

Thank you for the formula but I am not sure where to put it

You can use it Wherever you need these numeric values inside the loop.
It could be used in an assign activity: for eg:

numbersInFolderName = Regex.Match(folderName,“\d+”).Value

You can use this variable now wherever you need.

1 Like

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