Get folder file count

uiautomation
studio

#1

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?

How to count number of files inside a specific folder and open each file


Accessing a file inside the Progect FOlder
#2

HI @SudhakarAs,

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

Regards,
Arivu


#3

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.


#4

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.


#5

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