Small problem with my folder / file name grabber?

Blitz3D Forums/Blitz3D Beginners Area/Small problem with my folder / file name grabber?

Guy Fawkes(Posted 2013) [#1]
Hi! :) I wrote a small function which SHOULD grab the name of each file / folder (the user can select whether or not this includes file / folder incursion counting or just regular counting of files / folders in one folder directory), from the folder, and display it. Problem is, it's returning literally nothing at all (""). What am I doing wrong, here?

The problem is in the function I wrote, called "Grab_File_Names$(folder$, iwantfolder=0, iwantfiles=1)".

The function that allows CountDirs() & CountFiles() to return a value higher than or equal to 0, are because ScanDir() grabs the count of folders / files (incursively or not).

The functions:

Global DirCount, FileCount

Function Count_Dirs()
Return DirCount
End Function

Function Count_Files()
Return FileCount
End Function

Function Grab_File_Names$(folder$, iwantfolder=0, iwantfiles=1)

		myDir=ReadDir(folder$) 
	
		Repeat
		
			file$=NextFile$(myDir) 
	
			If file$="" Then Exit 
			
			If iwantfolder = 1 And iwantfiles = 0

				If Count_Dirs()<>0
	
						If file$<>"." And file$<>".." Then
								
							filenames$ = file$
							
							If filenames$<>""
							
								api_MessageBox(0, filenames$, "INFO", 0)
								
							EndIf
	
						EndIf
					
					Exit
					
				Else
				
					Exit
					
				EndIf
								
			Else If iwantfolder = 0 And iwantfiles = 1

				If Count_Files()<>0
	
						If file$<>"." And file$<>".." Then
								
							filenames$ = file$
							
							If filenames$<>""
							
								api_MessageBox(0, filenames$, "INFO", 0)
								
							EndIf
	
						EndIf
					
					Exit
					
				Else
				
					Exit
					
				EndIf
				
			EndIf

		Forever
		
		Return filenames$

End Function

Function ScanDir(folder$, recursive=1)

	If (recursive = 0 Or recursive = 1)

		myDir=ReadDir(folder$) 
	
		Repeat 
			file$=NextFile$(myDir) 
	
			If file$="" Then Exit 
		
			If FileType(folder$+"\"+file$) = 2 Then 
				If file$<>"." And file$<>".." Then
					If recursive Then ScanDir(folder$+"\"+file$)
					DirCount=DirCount+1
				EndIf
			Else 
				FileCount=FileCount+1
			End If 
		Forever 
	
		CloseDir myDir 
		
	Else
	
		api_MessageBox(0, "You can't get away with that!", "WARNING!", 0)
		
		End
		
	EndIf
	
End Function


Thank You!


Ross C(Posted 2013) [#2]
There are functions in the code archives to do this. Save you having to figure out whats wrong.


Guy Fawkes(Posted 2013) [#3]
Thanks, Ross :)


virtlands(Posted 2013) [#4]
Hi Thund,

The 'code archives' seem to only retrieve BlitzMax examples
when searching for 'directory search' code.


Guy Fawkes(Posted 2013) [#5]
Lolol, thanks, VirtLands. :P

I know you're trying to help, but I'm gonna get it out of my system, now..

EWWWWWWWWW! BLITZMAX! ><

XD