Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python for File Systems Project Starter Creating the Directory Structure

What is wrong with my code? why it shows the name is not defined?

from distutils.util import strtobool
import os
import pathlib
import re
import sys
import unicodedata

DIRS = [

def slugify(string):
    string = unicodedata.normalze("NFKC", string)
    string = re.sub(r'[^\w\s]', '', string).string().lower()
    return re.sub(r'[_-\s]+', '_', string)

def get_root():
  root = pathlib.PurePath(
    input("What is the full path where you would like the project?")
  if not root.is_absolute():
    return get_root()
  return root

def check_delete_rot(root):
    if os.path.exists(root):
        prrint("Path already exists.")
            delete = strtobool(input("Delete existing files/directories? [y/n] ").lower())
        except ValueError:
            return check_delete_root(root)
            if delete:
                except OSError:
                    print("Couldn't remove {}. Please delete it yourself.".format(root))
                    print("Delete {}".format(root))
def crete_dirs(root, slug):
    except OSError:
        print("Could not create the project root at {}.".format(root))
        for dir in DIRS:
                os.mkdir(os.path.join(root, dir.format(project_slug=slug)))
            except FileExistsError:

def main():
  project_root = get_root()
  project_name = None
  while not project_name:
    project_name = input("what is the full name for the project?").strip()
project_slug = slugify(project_name)

create_dirs(project_root, project_slug)

print("creating {} in {}".format(project_name, project_root))

if __name__ == '__main__':

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 68,239 Points

Please include the stacktrace information showing the error you are seeing.