Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python for File Systems Manipulation Daily Backup

james malloy
james malloy
7,959 Points

can't get past the backup.py challenge. directories not being created in workspace, but works on my pc

I'm using the following code, but can't see where I'm going wrong. Any suggestions would be welcome. TIA.

import os

def create_daily_dir(inp_dateString):

    # let's check the string format 
    dir_string = inp_dateString

    if dir_string[2] == "-":
        dir_string = inp_dateString[-4:] + "-" + inp_dateString[:2] + "-" + inp_dateString[3:5]

    # with the correct directory name in place, let's create it.
    os.makedirs( os.path.join("financial", dir_string), exist_ok=True)

create_daily_dir("04-22-2017")
backup.py
import os

def create_daily_dir(inp_dateString):

    # let's check the string format 
    dir_string = inp_dateString

    if dir_string[2] == "-":
        dir_string = inp_dateString[-4:] + "-" + inp_dateString[:2] + "-" + inp_dateString[3:5]

    # with the correct directory name in place, let's create it.
    os.makedirs( os.path.join("financial", dir_string), exist_ok=True)

create_daily_dir("04-22-2017")

2 Answers

Josh Keenan
Josh Keenan
20,315 Points

Here's the answer:

def create_daily_dir(inp_dateString):

    # let's check the string format 
    dir_string = inp_dateString

    if dir_string[2] == "-":
        dir_string = inp_dateString[-4:] + "-" + inp_dateString[:2] + "-" + inp_dateString[3:5]

    # with the correct directory name in place, let's create it.
    os.makedirs( os.path.join("financial", dir_string), exist_ok=True)

Your function works, just need to remove the call at the bottom... xD

james malloy
james malloy
7,959 Points

ouch - that's very, very frustrating. Thanks for spotting the issue. Regards, Jim