Finding all files of a certain type in a folder.


Well-known member
Jul 16, 2004
Programming Experience
How do I find out all files in a folder of a certain type, ex. .jpg or .bmp. And then go through them systematically to do a set thing to each one, such as resize them down to only 10% thier origenal size. I know how to change an individual images size, but only if the user tells it the exact path to the picture, not just a folder location...
Try something like this. You said you already know how to resize if you are given the filename, so you can either have a separate sub for jpgs and one for bmps, or combine them into one sub.

imports System.IO

	Public Sub ResizeImages(ByVal path As String)
		Dim dir As New DirectoryInfo(path)
		Dim file As FileInfo

		For Each file In dir.GetFiles
			Select Case file.Extension.ToLower
				Case "jpg"
				Case "bmp"
			End Select
	End Sub
Thanks for your help, I am going to get cracking on it immediately, I will make another reply telling you how it turns out.

That looks to be exactly what I was looking for with the folder searching and all.

<edit> Well, it worked perfectly, thanks for your help, I had been trying to figure out how to do that for a while now, and that was exactly what I needed.

I am making two different programs that needed this. One is a wallpaper randomizer that I wanted to make more user friendly, and the other is a program to make adding pictures to my website more efficient.