Directory determination problem
BlitzMax Forums/BlitzMax Programming/Directory determination problem
| ||
Hi. The following code works, but if I replace the . path with for instance c:\ only files are listed, as directories are not identified and parsed. This is on windows XP home Strict Function ListDir(path:String) Local dir:Int=ReadDir(path) Repeat Local t:String=NextFile( dir ) If t="" Exit If t="." Or t=".." Continue If (FileType(t) = 2) ListDir(path + "\" + t) Else Print path + "\" + t End If Forever CloseDir dir End Function ListDir(".") Just printing out the FileType codes yields 0 for all files/dirs on c:\ but correct 0,1 and 2 for files inside my test app directory?! What gives? |
| ||
I've resolved the same problem with thisFunction ScanDir(path:String,recursive=True,lvl=0) If path="" Then path=CurrentDir() Print "Scanning "+path If Right(path,1)<>"\" Then path=path+"\" Print "Path: "+path'If FileType(path)=0 Then Return mydir=ReadDir(path) counter=0 Repeat file$=NextFile(mydir) If file$="" Then Exit filename$=path$+file$ If FileType(filename)=1 counter=counter+1 Print String(lvl)+" [FILE] "+file$ else Print String(lvl)+" [DIR ] "+file$ If recursive=True If file$<>"." And file$<>".." If FileType(filename$)=2 lvl=lvl+1 scandir(filename$,True,lvl) End If End If End If End If Forever CloseDir mydir Return counter End Function Hope this useful - the problem is in the '\' |
| ||
Ahh smart. Works like a charm, thank you :) |
| ||
Can you use loaddir with skip_dots?Strict Function ListDir(mypath:String) Local files$[] files=LoadDir(mypath,True) For Local t$=EachIn files Print t Next End Function ListDir("c:") |
| ||
Nope. They are treated as "files", so you have to skip .. and . yourself. If that was what you meant :) |