Need to get total file count from main foldr

Hi All,

Have a requirement to get the count of total files from a folder where that main folder has few subfolders inside it


Hi @Harshita_D

Can you check this expression


This will give you the total count

Hi @Harshita_D

=> Drag and drop a “Assign” activity onto your workflow.

fileCount= Directory.GetFiles("C:\Your\Main\Folder", "*", SearchOption.AllDirectories).Length

=> Drag and drop a “Log Message” activity (or any other activity you want to perform with the file count) to display the fileCount variable.

Hope it helps!!

Hi @Harshita_D

To get the count of total files from a folder that contains subfolders, you can use the following steps in UiPath:

  1. Use the “Directory.GetFiles” Method:

    • Use the Directory.GetFiles method in UiPath to get a list of all files in the main folder and its subfolders.
    • You can use an Assign activity to assign the file paths to an array or list variable.
    filesArray = Directory.GetFiles("C:\YourMainFolder\", "*", SearchOption.AllDirectories)

    Replace "C:\YourMainFolder\" with the path to your main folder.

  2. Get the Count of Files:

    • After obtaining the list of file paths, you can use the filesArray.Length property to get the total count of files.

Here’s a simplified UiPath workflow to achieve this:

    - Assign (filesArray = Directory.GetFiles("C:\YourMainFolder\", "*", SearchOption.AllDirectories))
    - Assign (fileCount = filesArray.Length)
    - Log Message ("Total Files Count: " + fileCount.ToString)

Make sure to replace "C:\YourMainFolder\" with the actual path to your main folder. After running this workflow, the total count of files in the main folder and its subfolders will be displayed in the output log.


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