Take the 2-minute tour ×

I am writing a program with GTK where you press a button that says "RESET ALL". I need a function to be written that tells the program to erase every file in a specific folder. The folder is located at /home/marc/QuickJotProgram/QuickJotTexts QuickJotTexts is the folder that needs to be cleared. Keep in mind that the folder cannot be erased. /home/marc/QuickJotProgram/QuickJotTexts is bound to a variable called "SaveDir"

Thanks StackOverflow!

Here is some code that I tried to work with, but it tried to delete all the files in the program's folder, and not to the custom save directory

def reset_all(self):
    filelist = [ f for f in os.listdir(".") if f.endswith("") ]
    for f in filelist:
share|improve this question

1 Answer 1

Try this:

def reset_all(self):
    for f in os.listdir(SaveDir):
        os.remove(os.path.join(SaveDir, f))

Pass the SaveDir to os.listdir(SaveDir) this will return all file names in that folder. To generate full file path I have used os.path.join(SaveDir, f) to be used in os.remove()

share|improve this answer

Your Answer


