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 Manipulation Consistency

Not sure what to do

I'm guessing the question expects you to use regular expressions, but I have no idea how.

import os

# Filenames consist of a username (alphanumeric, 3-12 characters)
# and a date (four digit year, two digit month, two digit day),
# and an extension. They should end up in the format
# year-month-day-username.extension.

# Example: kennethlove2-2012-04-29.txt becomes 2012-04-29-kennethlove2.txt

def cleanup(path):
    # your code here
    for root, files, dirs in os.walk(path):
        for name in files:
            nameWithoutExtenstion = name.split('.')[0]
            nameExtension = name.split('.')[1]

            nameArray = nameWithoutExtension.split('-')
            newName = nameArray[1] + '-' + nameArray[2] + '-' + nameArray[3] + '-' + nameArray[0] + '.' + nameExtension

            os.rename(os.path.join(path, name), os.path.join(path, newName))