Getting filenames from a directory

Blitz3D Forums/Blitz3D Beginners Area/Getting filenames from a directory

Well, i got this code from...can't remember where, but:

; Define what folder to start with ...
folder$="images"

; Open up the directory, and assign the handle to myDir
myDir=ReadDir(folder$)

; Let's loop forever until we run out of files/folders to list!
Repeat
	; Assign the next entry in the folder to file$
	file$=NextFile$(myDir)
	
	; If there isn't another one, let's exit this loop
	If file$="" Then Exit
	
	; Use FileType to determine if it is a folder (value 2) or a file and print  results
	If FileType(folder$+""+file$) = 2 Then
		Print "Folder:" + file$
	Else
		If Lower(Right$(file$,3))="bmp" Then
			Print "File:" + file$
			file_count=file_count+1
		Else
			Print "File not supported:" + file$
		End If
	End If
Forever


file$=NextFile$(myDir)


Loads the next filename in the directory, into the string var file$. Just check the last three characters of the string, and match them against your file type. If they match, it's one of your files.