Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 urgent! trying to get a drectory listing to traverse subdirs
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
r0ssar00




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
beard0




PostPosted: Mon Jan 10, 2005 12:05 pm   Post subject: (No 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!
r0ssar00




PostPosted: Tue Jan 11, 2005 10:37 am   Post subject: (No 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
beard0




PostPosted: Tue Jan 11, 2005 10:46 am   Post subject: (No 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?
r0ssar00




PostPosted: Wed Jan 12, 2005 9:48 am   Post subject: (No subject)

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




PostPosted: Wed Jan 12, 2005 4:50 pm   Post subject: (No 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.



ReturnName.zip
 Description:
Produces a GUI window with customizable title, default file, and start directory and returns file name and path.

Download
 Filename:  ReturnName.zip
 Filesize:  125.46 KB
 Downloaded:  124 Time(s)

Hikaru79




PostPosted: Wed Jan 12, 2005 10:42 pm   Post subject: (No 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!
r0ssar00




PostPosted: Thu Jan 13, 2005 9:54 am   Post subject: (No subject)

thanx again, u just saved m project
Sponsor
Sponsor
Sponsor
sponsor
r0ssar00




PostPosted: Thu Jan 13, 2005 10:41 am   Post subject: (No 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)?
beard0




PostPosted: Fri Jan 14, 2005 7:54 am   Post subject: (No 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
r0ssar00




PostPosted: Fri Jan 14, 2005 10:37 am   Post subject: (No subject)

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




PostPosted: Fri Jan 14, 2005 10:42 am   Post subject: (No 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?
r0ssar00




PostPosted: Fri Jan 14, 2005 10:48 pm   Post subject: (No 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
beard0




PostPosted: Sat Jan 15, 2005 10:42 pm   Post subject: (No 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?
r0ssar00




PostPosted: Mon Jan 17, 2005 10:10 am   Post subject: (No 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 16 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: