How do I check a folder for files?

Blitz3D Forums/Blitz3D Beginners Area/How do I check a folder for files?

po(Posted 2004) [#1]
I am trying to make a picture viewer as a test. How do I check a certain folder for pictures? I want to make a screen which shows the pictures in a folder called: Pictures. I am using B3D.


GfK(Posted 2004) [#2]
Save this code to a .bb file, and put it in a folder with some images in it. Then run it with debug on.
scanfolder(CurrentDir$())

Function ScanFolder(Path$)
	Dir = ReadDir(Path$)
	Repeat
		File$ = NextFile(Dir)
		If File$ = "" Then Exit
		If IsGraphicsFile(Path$+File$) = True
			;SHOW IMAGE ETC
			DebugLog File$
		EndIf
	Forever
End Function

Function IsGraphicsFile(File$)
	file$ = Lower$(file$)
	ext$ = Right$(file$,3)
	If ext$ = "jpg" Or ext$ = "png" Or ext$ = "tga" Or ext$ = "bmp"
		Return True
	EndIf	
End Function



po(Posted 2004) [#3]
I ran it in debug and I saw all 3 of the pics in the log but i'm not sure how to list all the pics on the screen using text.


Bot Builder(Posted 2004) [#4]
lol. replace debuglog with print.


po(Posted 2004) [#5]
Errrmmm... I tried that :(
Heres what I got so far:

AppTitle "Picture Viewer"

Global picture,picture_x,picture_y,picture_speed

Graphics 800,600

SetBuffer BackBuffer()

scanfolder(CurrentDir$()) 

Function ScanFolder(Path$) 
Dir = ReadDir(Path$) 
Repeat 
File$ = NextFile(Dir) 
If File$ = "" Then Exit 
If IsGraphicsFile(Path$+File$) = True 
;SHOW IMAGE ETC 
DebugLog File$ 
EndIf 
Forever 
End Function 

Function IsGraphicsFile(File$) 
file$ = Lower$(file$) 
ext$ = Right$(file$,3) 
If ext$ = "jpg" Or ext$ = "png" Or ext$ = "tga" Or ext$ = "bmp" 
Return True 
EndIf 
End Function

While Not KeyHit(1)

Text 10,10,"All .bmp, .jpg, .png and .tga files within this folder:"
Text 10,25,CurrentDir$()

Flip
Cls

Wend
End 



picture=picture_load

Cls 

picture_mathH=ImageHeight(picture)/2
picture_mathW=ImageWidth(picture)/2
picture_x=400-picture_mathW
picture_y=300-picture_mathH

picture_speed=3

While Not KeyHit(1)

DrawImage picture,picture_x,picture_y

Text 400,300,"Height: "+picture_width
Text 400,315,"Width: "+picture_height

If KeyDown(200) :picture_y=picture_y-1*picture_speed:EndIf
If KeyDown(208) :picture_y=picture_y+1*picture_speed:EndIf
If KeyDown(203) :picture_x=picture_x-1*picture_speed:EndIf
If KeyDown(205) :picture_x=picture_x+1*picture_speed:EndIf

Flip
Cls

Wend



po(Posted 2004) [#6]
Ok...... I got it now.... But now I have another problem. I have too many images to fit on the screen in text, so I need a scroll bar type thing. A buttun so when you click it the text scrolls up for the up button and vise-versa for the down button. But how do I move all the text at once? I don't know the x,y coordinates of it. Or do I?
Graphics 800,600

counter=0
loc_x=0
loc_y=0

scanfolder(CurrentDir$()) 

Function ScanFolder(Path$) 
	Dir = ReadDir(Path$) 
	Repeat 
		File$ = NextFile(Dir) 
		If File$ = "" Then Exit 
		If IsGraphicsFile(Path$+File$) = True 
			;SHOW IMAGE ETC 
			;DebugLog File$
			counter=counter+1 
			Text loc_x,loc_y,File$
				                			loc_y=loc_y+15
		EndIf 
	Forever 
End Function

Do I have to move loc_y up or down somehow? I was thinking making all the text one image or something then moving the image up and down. Would that work?


eBusiness(Posted 2004) [#7]
Try making a string array and store the filenames there, then have a scrolling var and update the screen every time the user press a scroll key.