Using "Directory.Getfiles" exclude files with 0 file size

Thank you for your answer first.

I want to make an RPA with specific activities on “*.tif” files in a specific directory.
So, I used the string array and For each activity as follows:

Assign
Str_Array_Tif_file=directory.GetFiles(“Path”, “*.tif”)

ForEach ‘item’ in Str_Array_Tif_file
{Actions using Fileinfo(item)}

However, some errors occur with this RPA sometimes, because some of “tif” files has Zero size, so they cannot be opened in the RPA.

Therefore, I want to add only tif files with nonzero size to the string array in the first step. Please give me some advices.
Thanks.

@yhPark

You can check the file size inside the loop whether it’s greater than zero or not.

            ForEach item in Str_Array_Tif_file
            {Actions using Fileinfo(item)}
              IF Item.Length > 0
              Then Continue
               Else skip that file.

Hi,

Can you try the following?

Str_Array_Tif_file=directory.GetFiles("Path", "*.tif").Where(function(x) new FileInfo(x).Length>0).toArray

Regards,

1 Like

Thank you for your advice.

In my RPA, each tif file is classified by case and there are several different “For each activities” for each case. So, I have to insert the code into each of “For each activities” , according to your suggestion.
That’s why I want to add only tif files with nonzero size to the string array in the first step.

However, Thanks for your advice again.

1 Like

Thank you very much. It works perfectly.

1 Like

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