Search code examples
pythonraspberry-pipython-os

os.walk syntax error python


I am trying to get all directories from a specified root, this seems to run fine when I run it on windows by giving it a path, however when I move it to the raspberry pi I get a syntax error

 for root, dirs, files in os.walk("/home/pi/", topdown=False)
                                                           ^

I have been following this but not sure if I have been doing it correct: http://www.tutorialspoint.com/python/os_walk.htm, I have only just started with python so not sure what is wrong.

for root, dirs, files in os.walk("/home/pi/", topdown=False)
    for name in dirs:
        if name == "MyDir":
            createFolder = os.path.join(root, name)

Solution

  • You are missing a : after your for loop

    for root, dirs, files in os.walk("/home/pi/", topdown=False)
                                                                ^