vendredi 26 octobre 2018

My code that makes directories if none exist doesn't work as intended. Can you help me understand what's wrong with it?

I have this code that is supposed to make directories if none exist inside of my Documents folder. I'm not sure what's wrong with it. It makes the first folder, but won't make the next folder inside that. It doesn't raise an error, but it doesn't work either.

This is the code:

if not os.path.exists('C:\\Users\\NAME\\Documents\\MyGames'):
        os.chdir('C:\\Users\\NAME\\Documents')
        os.mkdir('MyGames')
        if not os.path.exists('C:\\Users\\NAME\\Documents\\Mygames\\PythonGames'):
            os.chdir('C:\\Users\\NAME\\Documents\\MyGames')
            os.mkdir('PythonGames')
            if not os.path.exists('C:\\Users\\NAME\\Documents\\MyGames\\PythonGames\\TextAdventure'):
                os.chdir('C:\\Users\NAME\\Documents\\MyGames\\PythonGames')
                os.mkdir('TextAdventure')

Aucun commentaire:

Enregistrer un commentaire