WHy was my post deleted.... Scanning Directory
BlitzMax Forums/BlitzMax Beginners Area/WHy was my post deleted.... Scanning Directory
| ||
I am not sure why it was deleted but I'll post it again.... I am trying to get a list of a directory and all its sub directories and get the files in each sub directory. I am using dir=ReadDir(CurrentDir()) If Not dir RuntimeError "failed to read current directory" Repeat t$=NextFile( dir ) If FileType(t) = 2 Then Print t ElseIf FileType(t) = 1 Then Print t ElseIf FileType(t) = 0 Then Exit EndIf Forever CloseDir dir End But for some reason it isnt giving me the sub directories any help is appreciated thanks. |
| ||
Well it gives the subdirectories on mine. It doesnt "scan" the subdirectories, but the you havent any code to do that, so you probably know that already. You want to make it a function containing your repeat loop, that accepts a "dir handle" as its paramater (dir in you example), (Or just pass the path). Then when you find a subdirectory, (pass the path or), Make it current, and pass that handle to itself. If you keep a Global in the function which keeps a track of how "deep" you are, you can print a tab indent as well |
| ||
LOOKS LIKE THERE WAS A PROBLEM LAST NIGHT - LOOKS LIKE A FEW HOURS OF POSTS HAVE BEEN LOST. |
| ||
Yeah, I noticed that too. Or maybe we're experiencing some weird temporal anomaly. |
| ||
Aliens! |
| ||
Damnit, it actualy comes to a problem that I can help someone fix, and the post is deleted, grr Basicly, you never tell it to scan sub directories, this is what makes a Programming Language a Programming Language, rather than a Scripting Language, there is no automatic, you do everything yourself Think about what would happen if this code did scan sub directories, where would that leave people who only did want the first layer? Automatic creates limitations, so get used to doing it yourself Now then, what you would need to make this automaticly scan sub directories would be a list containing all the names you found in the folder, once you finish scanning layer1, you go back through the list and scan every name in the list as well, and so on and so forth until there are no layers left to scan |
| ||
Why was it deleted? http://www.blitzbasic.com/Community/posts.php?topic=63502 |
| ||
sorry didnt see that. |
| ||
FileList("C:\windows",True) Function FileList(Folder:String,Recurse:Int) Local ThisFolder:Int = ReadDir(Folder) If ThisFolder Repeat Local File:String = NextFile(ThisFolder) If Len(File) Select FileType(Folder + "\" + File) Case 1 Print Folder + "\" + File Case 2 Select File Case ".",".." Default If Recurse Then FileList(Folder + "\" + File,Recurse) End Select End Select Else Exit End If Forever CloseDir ThisFolder End If End Function |