In the code below I have a class that handles what folder the user is in, so they can browse through multiple folders. I know that this isn't going to work right just yet.

This is the first time I've tried using classes and I don't understand them so well. So I probably mucked something up somewhere.

This code seems like it's going to work, but I get an odd error when it tries to print the contents of the folder the user types.

class GetFoldersInDir:
    def DirName(self,directory):
        os.system("cls") = directory
        print "Folders in %s\n" % directory
        for folder in os.listdir(directory):
            print folder

def delete():

    Get = GetFoldersInDir()
    choice = raw_input("\nType del to delete something, type a folder's name to open it.\n")

    if choice == "del":
        print "@@@@@@"
    elif choice in os.listdir(
        print "Folder not found."

WindowsError: [Error 3] The system cannot find the path specified: 'Old/*.*'
Why does it add /*.* to what I type? :?:

and wheres the code of that part where you type a folder name to see it's contents.

Something to this direction, if I understood your intention?

import os
class Folder:
    def __init__(self, path):
        if os.path.isdir(path):
            raise WindowsError, 'Invalid path name: '+path
    def __str__(self):
        res = "Folders in %s\n" % self.path
        return res+'\n\t'.join( filter(os.path.isdir,
                                        for p in os.listdir(self.path)]))
    def cd(self,directory):
        curdir = os.path.join(self.path, directory)
        if os.path.isdir(curdir):
            self.path= os.path.realpath(curdir)
            return curdir
            return False
def delete():
    print """
    Type del to delete something,
    type a folder's name to open it,
    enter empty line to quit.
    while True:
        print myfolder
        choice = raw_input('>')

        if not choice:
        elif choice == "del":
            print "dummy del",myfolder.path
        elif not
            print "Folder not found."

myfolder = Folder("D:/")

YES! That is exactly what I was trying to do. Thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.