recursive directory search - help plz

BlitzMax Forums/BlitzMax Programming/recursive directory search - help plz

slenkar(Posted 2009) [#1]
trying to edit my blitzmax files with a blitzmax program (to correct 51 lines in different files)

heres my code
' readdir.bmx

thisdir$=CurrentDir()

If Not thisdir RuntimeError "failed to read current directory"
Print "current dir: "+thisdir
read_dir(thisdir)



Function Read_Dir(dir$)
Global timer=CreateTimer(60)
the_dir=ReadDir(dir)

Repeat
	
	WaitTimer(timer)
	
	t$=NextFile( the_Dir )
	Print t+" nextfile"
	
	
	If t<>"."
	If t<>".."
	If ExtractExt(t)<>"bmx"
	If FileType(t)=2
	Print ExtractExt(t)+" directory "+t
	read_dir(t)
	EndIf
	EndIf
	EndIf
	EndIf
	
	If FileType(t)=1
	If t<>"." And t<>".."
	If ExtractExt(t)="bmx"
	
	Print t+" blitzmax file"
	
	EndIf
	EndIf
	EndIf
	
	If t="" Exit

Forever

CloseDir the_dir
EndFunction


I run the program from inside my module and I want it to read all subdirectories in the module
thing is it runs in an infinite loop just reading the first mod folder in the directory!

does anyone know why?


_Skully(Posted 2009) [#2]
' readdir.bmx

thisdir$=CurrentDir()

If Not thisdir RuntimeError "failed to read current directory"
Print "current dir: "+thisdir
read_dir(thisdir)

Function Read_Dir(dir$)
	the_dir=ReadDir(dir)
	Repeat
		t$=NextFile( the_Dir )
		Print t+" nextfile"
		If t<>"." And t<>".."
			If FileType(t)=2
				read_dir(t)
			ElseIf ExtractExt(t)="bmx"		
				Print t+" blitzmax file"
			EndIf
		EndIf
	Until t=""
	CloseDir the_dir
EndFunction



slenkar(Posted 2009) [#3]
that also does an infinite loop


Jason W.(Posted 2009) [#4]
It's looks like your Return value might be wrong. I think checking for t = " " might be a valid value.

Try either of these checks:

t = ""
t =0
t=null

I'm not at home to test this, so I'm going from memory.

Jason


_Skully(Posted 2009) [#5]
It works here without an infinite loop.

I tested it before I uploaded as well... are you using Linux? Linux has hard/soft links in its directory structure that could cause this code to do an infinate loop.


slenkar(Posted 2009) [#6]
no, windowsXP I got a different bit of code from the archives and that works, dont know why this one doesnt work for me.