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

Create daily dir not being accepted

Hi,

I've created the function, but I am getting an error message that I am not getting the right response for (year-month-day) input.

Anybody knows whats going wrong?

Jair

backup.py
import os

def create_daily_dir(date_string):
    date_string_splitted = date_string.split("-")
    if len(date_string_splitted[0]) != 4:
        date_string = date_string_splitted[2] + "-" + date_string_splitted[0] + "-" + date_string_splitted[1]
    total_path = os.path.join(os.getcwd(), date_string)
    os.makedirs(total_path, exist_ok=True)
    return None

1 Answer

Bart Bruneel
Bart Bruneel
27,212 Points

Hello Jaïr,

You should change the following line in your solution:

total_path = os.path.join(os.getcwd(), date_string)

to

total_path="financial/"+date_string

If you use os.getcwd() you will get the whole path to the current working directory from the root, so if you join it with your date_string and use os.makedirs you will get all of the folders in the joined path inside of your current working directory.

Hope this helps,

Bart