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

aaron g
aaron g
15,142 Points

I'm trying to write a Python program that would rename files in a folder. I start out asking the user for a folder path

I'm trying to write a Python program that would rename files in a folder. I start out asking the user for a folder path but I get an error that says: “No such file or directory:” and gives the folder path. It also, gives an error on line 5, in <module> names = os.listdir(path). I copy the folder path in Terminal, so it shouldn’t be a mistyped error.

This is my code:

  '''python

  import os, sys

  path = input("Give me a folder path ")
  names = os.listdir(path)

  counter = 0
  evenNum = -2

  for filename in names:
                os.rename(filename, '{}_1forward_{}+00_E'.format(counter, evenNum))
                counter += 1
                evenNum += 2

  '''

I have been working on this problem for weeks. I would appreciate anyone's help. Thanks