How to check if the folder is empty or not?

how to check if the folder is empty or not?

@kararora Follow this link

2 Likes

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

2 Likes

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.

2 Likes

thankyou karthick , it worked :slight_smile:

thankyou arivu :slight_smile:

Hello Karan

1 Like

Where in uipath are you gonna write this code? Thanks

1 Like

@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

1 Like

hello Karaora can you upload the file.

Use this code

1 Like

thanks for sample code

Hi Naresh,
Hope so, code will resolve your issue.

If you need any further assistance let me know.

Regards,

Avanish

concat string sapmle code could u share?

Wont work for me :confused: I have a variable with the Folderpath as string.

want to check if the folder its empty or not. It will contain only pdf files