Computer Science Canada

urgent! trying to get a drectory listing to traverse subdirs

Author:  r0ssar00 [ Sun Jan 09, 2005 12:43 am ]
Post subject:  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 )
code:

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

Author:  beard0 [ Mon Jan 10, 2005 12:05 pm ]
Post subject: 

code:
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!

Author:  r0ssar00 [ Tue Jan 11, 2005 10:37 am ]
Post subject: 

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

Author:  beard0 [ Tue Jan 11, 2005 10:46 am ]
Post subject: 

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?

Author:  r0ssar00 [ Wed Jan 12, 2005 9:48 am ]
Post subject: 

its due for friday, thanku thanku, i cant say thank u enuf

Author:  beard0 [ Wed Jan 12, 2005 4:50 pm ]
Post subject: 

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.

Author:  Hikaru79 [ Wed Jan 12, 2005 10:42 pm ]
Post subject: 

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!

Author:  r0ssar00 [ Thu Jan 13, 2005 9:54 am ]
Post subject: 

thanx again, u just saved m project

Author:  r0ssar00 [ Thu Jan 13, 2005 10:41 am ]
Post subject: 

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)?

Author:  beard0 [ Fri Jan 14, 2005 7:54 am ]
Post subject: 

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.
code:
function StrUpper (txt:string):string
     var txt2:=""
     for i:1..length(txt)
          if txt(i)>="a" and txt(i)<="z" then
               txt2(i)+=chr(ord(txt(i))+ord("A")-ord("a"))
          else
               txt2(i)+=txt(i)
          end if
     end for
end StrUpper

Author:  r0ssar00 [ Fri Jan 14, 2005 10:37 am ]
Post subject: 

i have 4.0.4c, can ne 1 post the updated GUI module and the updated str module or is that against copyrights?

Author:  beard0 [ Fri Jan 14, 2005 10:42 am ]
Post subject: 

the str module is built in, but i gave you the fucntion that does the same thing. As for the GUI module, I gave you my custom one, which you need to run the prgram I gave you. My program simply doesn't work with holt's GUI because I added new commands. Did you try the not File.Exists method?

Author:  r0ssar00 [ Fri Jan 14, 2005 10:48 pm ]
Post subject: 

evrything works unmodified at home w/4.0.5, but one thing, in line 134 of WidgetModule.tu, it errs w/keyboard input from invisible input not allowed, ne suggestions?, also, who made the graphics, they did a nice job, now if there was only a way to get rid of the titlebar and frame

Author:  beard0 [ Sat Jan 15, 2005 10:42 pm ]
Post subject: 

Can you tell me what to do to create the error message? And by getting rid of title bar and "frames" do you mean make it full screen? Otherwise, what frames are you talking about?

Author:  r0ssar00 [ Mon Jan 17, 2005 10:10 am ]
Post subject: 

first, the title bar was just a though, not a question, second the way to recreate the error message is to create a program that utilizes the Win.SaveOpen fcn
code:
var fileToSaveOpen : string := Win.SaveOpen ("OPEN", ".t", "c:\\")

then run it

Author:  r0ssar00 [ Mon Jan 17, 2005 10:32 am ]
Post subject: 

actually, that does work, but i forgot to add something to it
better yet, ill give u the project with all the stuff leading up to the error (and a little bit past that)


: