Steven Zack
Steven Zack

Reputation: 5114

How do I list all images in a folder using C#?

I need to list all of the images in a folder using C#.

I searched Stack Overflow and found some threads talking about it, but the questions were covering PHP. I need to do this with C#.

Upvotes: 3

Views: 14323

Answers (3)

user596075
user596075

Reputation:

DirectoryInfo di = new DirectoryInfo(@"C:\YourImgDir");

FileInfo[] Images = di.GetFiles("*.jpg");

You can substitute whatever image file extensions you so desire.

Upvotes: 6

MyKuLLSKI
MyKuLLSKI

Reputation: 5325

This is for C#:

string[] files = Directory.GetFiles("Location of Files", "*.jpg"); //.png, bmp, etc.

Upvotes: 5

Brissles
Brissles

Reputation: 3891

You can use Directory.GetFiles to get the filenames of files in a directory:

var files = Directory.GetFiles("directory_path", "*.jpg"); 

You can change .jpg for any other file type. The asterisk is a wildcard character.

Upvotes: 2

Related Questions