
-----------------------------------
r0ssar00
Sun Jan 09, 2005 12:43 am

urgent! trying to get a drectory listing to traverse subdirs
-----------------------------------
hi, i am trying to traverse subdirectories in my final project and it wont get the second, or for that matter, the third subdir's listing, please help, here's my listing code
( by the way, its been 2 days since my first post on this, its kind of urgent )

import GUI
var driveChooseWin : int := Window.Open ("graphics:850;300,nobuttonbar,position:center;truemiddle,title:Choose the Drive")
var stream : int
var files:array 1..5000 of string
var continue : int := 0
Window.SetActive (driveChooseWin)
GUI.SetBackgroundColour (black)
locate (1, 1)
Text.Colour (white)
Text.ColourBack (black)
put "Choose the drive and Folders.  Select one only"
put "(one chance to select), "
put "or else an unresolved error will"
put "occur."
Text.Colour (black)
Text.ColourBack (white)
proc setContinue
    continue := 1
end setContinue
var fileToOpen : string
var drive : string
var listing : int
var dirToOpen : string := ""
proc driveChooser (x : int)
    if x = 1 then
        if stream not= 0 then
            Dir.Close (stream)
            drive := "A:/"
            stream := Dir.Open (drive)
            put stream
        else
            drive := "A:/"
            stream := Dir.Open (drive)
            put stream
        end if
    elsif x = 2 then
        if stream not= 0 then
            Dir.Close (stream)
            drive := "C:/"
            stream := Dir.Open (drive)
        else
            drive := "C:/"
            stream := Dir.Open (drive)
        end if
    elsif x = 3 then
        if stream not= 0 then
            Dir.Close (stream)
            drive := "E:/"
            stream := Dir.Open (drive)
        else
            drive := "E:/"
            stream := Dir.Open (drive)
        end if
    elsif x = 4 then
        if stream not= 0 then
            Dir.Close (stream)
            drive := "H:/"
            stream := Dir.Open (drive)
        else
            drive := "H:/"
            stream := Dir.Open (drive)
        end if
    elsif x = 5 then
        if stream not= 0 then
            Dir.Close (stream)
            drive := "F:/"
            stream := Dir.Open (drive)
        else
            drive := "F:/"
            stream := Dir.Open (drive)
        end if
    end if
    continue := 0
end driveChooser
var dirs : array 1 .. 5000 of string

var fileToSaveTo : string
proc dummy (x : int)
    fileToOpen := files (x)
    fileToSaveTo := dirToOpen + "/" + files (x)
end dummy
var boxChoice : int := 1
proc dummyDir (x : int)
    if dirs (x) = "" then
        dirs (x) := "."
    else
        dirToOpen := drive + dirs (x)
    end if
end dummyDir
proc dummyDir2
    continue := 1
    Window.Hide (driveChooseWin)
end dummyDir2
var size, attribute, fileTime : int
var fileName : string
var offsetx : int := 0
var Continue : int
proc Continues
    var i : int := 1
    for t : 1 .. 5000
        dirs (t) := intstr (t)
    end for
    i := 1
    var Continue3 := GUI.CreateButton (180, 10, 0, "Choose Directory", Continues)
    var Continue4 := GUI.CreateButton (350, 10, 0, "Choose Directory", Continues)
    var Continue5 := GUI.CreateButton (520, 10, 0, "Choose Directory", Continues)
    GUI.Hide (Continue3)
    GUI.Hide (Continue4)
    GUI.Hide (Continue5)
    listing := GUI.CreateTextBoxChoice (maxx div 2 div 2 + offsetx, maxy div 2 div 2, maxx div 2 div 2, maxy - 150, 0, 0, dummyDir)
    if boxChoice = 1 then
        GUI.Hide (Continue)
        GUI.Show (Continue3)
    elsif boxChoice = 2 then
        GUI.Hide (Continue3)
        GUI.Show (Continue4)
    elsif boxChoice = 3 then
        GUI.Hide (Continue4)
        GUI.Show (Continue5)
    elsif boxChoice = 4 then
        GUI.Hide (Continue5)
    end if
    loop
        Dir.GetLong (stream, fileName, size, attribute, fileTime)
        if (attribute and ootAttrDir) not= 0 then
            GUI.AddLine (listing, fileName)
            dirs (i) := fileName
            i += 1
        end if
        exit when fileName = ""
    end loop
    offsetx += 212
    boxChoice += 1
end Continues
var driveListing := GUI.CreateTextBoxChoice (50 - 25, maxy div 2 div 2, maxx div 2 div 2 - 25, maxy - 200, 0, 0, driveChooser)
GUI.AddLine (driveListing, "A:\\")
GUI.AddLine (driveListing, "C:\\")
GUI.AddLine (driveListing, "E:\\")
GUI.AddLine (driveListing, "H:\\")
GUI.AddLine (driveListing, "F:\\")
Continue := GUI.CreateButton (10, 10, 0, "Choose Directory", Continues)
var Continue2 := GUI.CreateButton (maxx - 80, 10, 0, "Proceed", dummyDir2)
loop
    exit when GUI.ProcessEvent
    exit when continue = 1
end loop

thanx

-----------------------------------
beard0
Mon Jan 10, 2005 12:05 pm


-----------------------------------
View.Set("text")
proc listdir (dir : string, level : int)
    if Dir.Exists (dir) then
        var startdir := Dir.Current
        Dir.Change (dir)
        var str := Dir.Open (Dir.Current)
        var fname : string
        loop
            fname := Dir.Get (str)
            exit when fname = ""
            if fname not="." and fname not=".." then
            put repeat ("   ", level) ..
            put fname
            listdir (fname, level + 1)
            end if
        end loop
        Dir.Change (startdir)
    end if
end listdir
put Dir.Current
listdir(Dir.Current,1)
Enjoy!

-----------------------------------
r0ssar00
Tue Jan 11, 2005 10:37 am


-----------------------------------
i dont think u got the code, what im trying to do is to produce a GUI box that u can choose a directory in and then the next box will show up, and then u choose the next subdir in that and so on , up to three subdirs from the root

-----------------------------------
beard0
Tue Jan 11, 2005 10:46 am


-----------------------------------
I've got the code for exactly that at home.  It is a function that returns the selected file's name.  I'll post tonight.
What's the rush anyway?

-----------------------------------
r0ssar00
Wed Jan 12, 2005 9:48 am


-----------------------------------
its due for friday, thanku thanku, i cant say thank u enuf

-----------------------------------
beard0
Wed Jan 12, 2005 4:50 pm


-----------------------------------
It uses an extended GUI written by Sean Hayward, another compsci member, which I further extended for my own uses.  I have included this in the zip.  Run example.t to see how to work it.  Enjoy!


Oops, forgot to say: If you want to start at the listing of all drives available(it recognizes which letter names are valid), use "" as your starting directory.

-----------------------------------
Hikaru79
Wed Jan 12, 2005 10:42 pm


-----------------------------------
Wow, beard0, that's an excellent idea! I don't have Turing so I can't really test if it works, but if it does, it's a great tool, and I'll give you the benefit of the doubt.

+20 bits!

-----------------------------------
r0ssar00
Thu Jan 13, 2005 9:54 am


-----------------------------------
thanx again, u just saved m project

-----------------------------------
r0ssar00
Thu Jan 13, 2005 10:41 am


-----------------------------------
slight problem though Win.SaveOpen errors at Str.Upper and Dir.Exists
this is how i installed this:
extract to %oot\S_Engine
might it be written improperly (or have i installed it wrong?)?
i kept the original lib folder intact it has not been modified, should i instead put S_Engine into another area (not %oot but C:\S_Engine)?

-----------------------------------
beard0
Fri Jan 14, 2005 7:54 am


-----------------------------------
You don't have version 4.0.5 do you?
Replace Str.Upper with StrUpper, and place this function at the top of the module.
Try replacing "Dir.Exists" with "not File.Exists".
I can't guarantee this working, but it's worth a try.
function StrUpper (txt:string):string
     var txt2:=""
     for i:1..length(txt)
          if txt(i)>="a" and txt(i)