Compare two files in a folder to find the smallest one in size

Hello,

I am looking to find the smallest amongst 2 files in a folder with respect to its size in KB.
So far I was trying the below logic to save the file size in an array, but I am not able to achieve this.

Is there a way to simply read the size of files in folder and find the smallest instead of reading size of each file and then saving their size in array and finding which is smallest?

Lets assume we do have a folder c:\Data
which contains a multiple files

So we can find the file with smallest size e.g. by

Assign Activity
mySmallestFile | DataType: FileInfo =
new DirectoryInfo("myFolderPath").GetFiles().OrderBy(Function (x) x.SizeInKB).First()

UPD1 - Added Info Resource Links
Also have a look here:

I tried this and it does work. Unfortunately this is not how I need the result.

I have many files in the folder with multiple names:

  1. I need to first filter the files with same name
  2. then I need to find the type .pdf
  3. then I need to find the smallest of them in size.
    So, I have array of files (2 files with same name) and I need to find the smallest in size amongst these 2. So I cant use the GET Directory function.

we recommend to present all requiements always at the begin. So, we can adress more specific

we cannot derive what is meant with same name. Just share with us some samples. When it is about a common part of the name, then we would grouping the data

this we can already done on the file filtering

new DirectoryInfo("myFolderPath").GetFiles("*.pdf").OrderBy(Function (x) x.SizeInKB).First()

in general as done above.

Once you shared with us the requested details, then we will update our solution suggestion

1 Like

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