Get folder file count

Hi - I referred the below solution to get the number of files in a folder…
But i am facing an error. Can someone help me understand that better.

What is wrong in using a variable(locn) instead of providing the folder path directly?

https://forum.uipath.com/t/how-to-count-number-of-files-inside-a-specific-folder-and-open-each-file/3533![folderUnzip|690x291](upload://fu0GogziwjcczEvtxUWrOH4huCI.JPG)

HI @SudhakarAs,

refer this xaml file to get File count from the folder.
GetFileCount.xaml (6.5 KB)

Regards,
Arivu

2 Likes

Hey @SudhakarAs

Not sure but I believe you will get that error when you initialize your variable ‘DirectoryPath’ without setting a value for ‘iocn’ variable. I am not a master in programming but seems like all the variables are set before the workflow is executed when run. Hence in that case if ‘iocn’ variable doesn’t have a value set, ‘DirectoryPath’ variable would not be initialized and error is thrown. I believe even if you change the path of the ‘iocn’ using assign activity from workflow, it would still take the old one set inside the variable because ‘DirectoryPath’ would have already been initialized at that time.

Thanks,
Rammohan B.

Thanks Ram. I got that.

I would like to understand whether any precedence is followed in variable declaration in that variables pane.
When i have declared “locn” ahead of “DirectoryPath” i am not getting any exceptions.
It did fine.

Hi @SudhakarAs ,
You can get the file count in a directory by using the simple c# code
Directory.GetFiles(“directory path”). Length

3 Likes