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

Hi
I would like to count number of files inside a specific folder and open each file or only .png files. can anyone know about this??

you can use
System.IO.DirectoryInfo myDir= new System.IO.DirectoryInfo(“SourcePath”);
int count = myDir.GetFiles().Length;
or below approach as well.

Hey @Sunitha_Bist

you can use for-each looping construct with Directory.GetFiles("FOLDER_PATH","*.*",SearchOption.AllDirectories) and inside it using If condition by using Path.GetExtension(item)=“.png”.

for reference flow understanding for you:sample.xaml (7.1 KB)

Note- Replace the folder path with your directory path.

Regards…!!
Aksh

12 Likes

tq aksh… it worked for me :slight_smile:

Hi,
I want to do exactly the same but with excel-files. I do Path.GetExtension(item)=“.xls”. But this throws me an error: " …Disallows implicit conversions from ‘Object’ to ‘String’ " … Any ideas what Im doing wrong?

EDIT: Wrong type argument. :smiley:

GO to for Each → TypeArgument → Change TypeArgument from Object to String :grinning: