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

Username:   Password: 
 RegisterRegister   
 Displaying filenames in folders
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Srlancelot39




PostPosted: Fri Dec 02, 2011 5:18 pm   Post subject: Displaying filenames in folders

What is it you are trying to achieve?
Is there a way to get the names of all files in a folder and display them? I have an RPG (Grail Quest) that allows the user to save their game and load it later and I would like to build on this by letting them create multiple save files and then select it from a list later so they can load it.

(Also, is there a way to write/read files from different folders without knowing the full pathname? Not every user is going to have the game's files under the same pathname so unless the setting 'Display full pathnames' is off, this will cause problems.)


What is the problem you are having?
Not sure what command to use for this.


Describe what you have tried to solve this problem
The closest I've gotten is using the 'system' function to search/open specific files.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
I don't think there's any code I could put here that would help


Please specify what version of Turing you are using
4.1 <----because it can compile Razz

EDIT: I have, in the meantime, found a command that may solve my problem. The command I have found is Dir.Get/Dir.Open. I have successfully reading the folder "Turing 4.1" on my desktop, however the first two lines are "." and ".." then after that the files/folders are listed. How do I stop it from displaying the dots (and why are they there)?
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Fri Dec 02, 2011 5:57 pm   Post subject: RE:Displaying filenames in folders

Say your game is in mydirectory/game.exe
If you keep all your savegames in mydirectory/savegames, then in your game you need only to load savegames/mysavefile.ext.

You've basically got 2 path types: An absolute path, and a relative path. An absolute path is the path from the root directory (C:\, for example) to the file. A relative path is the path from any location to any other. This is where the dots come in.

The single dot represents a file's self. mydirectory/game.exe = ././mydirectory/././game.exe

The double dot represents a file's parent.

mydirectory/game.exe = mydirectory/../mydirectory/game.exe.

This comes in useful when you have all your game files in Game/bin/game.exe, and all your data in Game/Resources/Pictures. To access your picture files, inside game.exe you call Pic.FileLoad (../Resources/Pictures/sprite.jpg)

So, as long as you know where your save files are (relative to your executable), you don't ever need to look through the file system.
Srlancelot39




PostPosted: Fri Dec 02, 2011 7:32 pm   Post subject: Re: Displaying filenames in folders

Perfect, thanks!

Also, I managed to get the code working. This is what I have:

Turing:


% The "DirectoryListing" program.
setscreen ("graphics:500;500, offscreenonly")
var streamNumber : int
var fileName : array 1 .. 5 of string
streamNumber := Dir.Open ("D:\\Desktop\\Test")
var filenumber : int
filenumber := 1
assert streamNumber > 0
var font1 : int
font1 := Font.New ("Courier:12")
var xmouse, ymouse, button : int
var filenumberhighlight : int
var success : int

loop
    fileName (filenumber) := Dir.Get (streamNumber)
    if fileName (filenumber) not= "." and fileName (filenumber) not= ".." then
        Font.Draw (fileName (filenumber), 0, 525 - filenumber * 50, font1, black)
        filenumber := filenumber + 1
    end if
    exit when filenumber = 6
end loop
Dir.Close (streamNumber)

loop
    mousewhere (xmouse, ymouse, button)
    if ymouse < 501 and ymouse > 450 then
        filenumberhighlight := 1
        if button = 1 then
            system ("D:\\Desktop\\Test\\" + fileName (filenumberhighlight), success)
            exit
        end if
    elsif ymouse < 451 and ymouse > 400 then
        filenumberhighlight := 2
        if button = 1 then
            system ("D:\\Desktop\\Test\\" + fileName (filenumberhighlight), success)
            exit
        end if
    elsif ymouse < 401 and ymouse > 350 then
        filenumberhighlight := 3
        if button = 1 then
            system ("D:\\Desktop\\Test\\" + fileName (filenumberhighlight), success)
            exit
        end if
    elsif ymouse < 351 and ymouse > 300 then
        filenumberhighlight := 4
        if button = 1 then
            system ("D:\\Desktop\\Test\\" + fileName (filenumberhighlight), success)
            exit
        end if
    elsif ymouse < 301 and ymouse > 250 then
        filenumberhighlight := 5
        if button = 1 then
            system ("D:\\Desktop\\Test\\" + fileName (filenumberhighlight), success)
            exit
        end if
    else
        filenumberhighlight := 0
    end if
    for f : 1 .. 5
        Font.Draw (fileName (f), 0, 525 - f * 50, font1, black)
    end for
    if filenumberhighlight > 0 and filenumberhighlight < 6 then
        drawfillbox (0, 500 - filenumberhighlight * 50, 500, 550 - filenumberhighlight * 50, black)
        Font.Draw (fileName (filenumberhighlight), 0, 525 - filenumberhighlight * 50, font1, brightred)
    end if
    View.Update
    cls
end loop



Coincidentally, the part of my problem that you replied to is the only part I hadn't solved yet!
Thanks again!
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 1  [ 3 Posts ]
Jump to:   


Style:  
Search: