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

Username:   Password: 
 RegisterRegister   
 Scanning a Directory
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Prince Pwn




PostPosted: Sun Feb 04, 2007 12:05 am   Post subject: Scanning a Directory

I'm working on a Music Player and when you execute it, I want a main directory (such as c:/.../my music/) and it goes through all folders within that main directory and store each .mp3 inside an array (or a file). eg:

---C:/Music/
-------------/Greenday/
-------------------------American Idiot.mp3
-------------------------Jesus of Suburbia.mp3 #don't know how to return to main folder & continue scanning
------------/Black Eyed Peas/
-------------------------My Humps.mp3
-----------/The Vapors/
-------------------------Turning Japanese.mp3

The trouble I am having is once inside a folder, returning to the main folder and continue scanning all of them until the bottom. I've been trying to do this for a few months now and cannot get it right. Could anyone assist me in this? It is not for a school project because we're done with Turing and moving onto Java in grade 12 and I "passed Turing" lol. Thanks.
Sponsor
Sponsor
Sponsor
sponsor
rdrake




PostPosted: Sun Feb 04, 2007 1:25 am   Post subject: RE:Scanning a Directory

Not sure if this helps or not, but "../" points to the parent directory.
Prince Pwn




PostPosted: Sun Feb 04, 2007 2:55 pm   Post subject: Re: Scanning a Directory

Here is directly from the Turing help:
Turing:

% The "DirectoryListing" program.
setscreen ("text")
var streamNumber : int
var fileName : string
streamNumber := Dir.Open (".")
assert streamNumber > 0
loop
    fileName := Dir.Get (streamNumber)
    exit when fileName = ""
    put fileName
end loop
Dir.Close (streamNumber)


I know how to do the above, it's just I need help with making an if statement that will know if it's a file or a directory (tried Dir.Exists but wasn't working) then opening that file and scan it then go back ".." or "." and go to the next folder.
ericfourfour




PostPosted: Sun Feb 04, 2007 11:40 pm   Post subject: Re: Scanning a Directory

I made a function that returns a linked list of the filenames.

Turing:
type StrList :
    record
        next : ^StrList
        str : string
    end record

fcn getDir (streamNumber : int) : ^StrList
    var list : ^StrList
    new list
    var current := list
   
    loop
        current -> str := Dir.Get (streamNumber)
        exit when current -> str = ""
        new current -> next
        current := current -> next
    end loop

    result list
end getDir


A sample program:

Turing:
setscreen ("text")

var streamNumber : int
var fileName : string
streamNumber := Dir.Open (".")
assert streamNumber > 0

var listing := getDir (streamNumber)
var current := listing

loop
    exit when current -> str = ""
    put current -> str
    current := current -> next
end loop
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  [ 4 Posts ]
Jump to:   


Style:  
Search: