How to check if the folder is empty or not?

uiautomation
studio

#1

how to check if the folder is empty or not?


#2

@kararora Follow this link


#3

Hi @kararora,

strdirPath="D:\Arivu\FolderName"

in If condition check the folder is empty or not.
If(Directory.GetFiles(strdirPath).Length == 0 && Directory.GetDirectories(strdirPath).Length == 0)

True->Folder is empty

Regards,
Arivu


#4

Directory.GetFiles(path, “*”, SearchOption.TopDirectoryOnly).Length will gives you Count of Files in the particular folder.

Directory.GetFiles(path, “*”, SearchOption.AllDirectories).Length will gives you Count of Files in the particular folder with subfolder file Count.


#5

thankyou karthick , it worked :slight_smile:


#6

thankyou arivu :slight_smile:


#7

Hello Karan


#8

Where in uipath are you gonna write this code? Thanks


#9

@cyruspogii based on your requirement you can use this code, if you simply want a count and save it. You can right this code in assign activity.

If you want to do further operation based on the result then use in if condition as per the above questions requirement.

Take 1 If activity, in the condition part write down
Directory.GetFiles(strdirPath).Length == 0 && Directory.GetDirectories(strdirPath).Length == 0

as per requirement write data in true and false part. For your reference I am attaching a sample code.Test1.xaml (6.2 KB)

Regards,
Avanish