renaming files

This is the place for queries that don't fit in any of the other categories.

renaming files

Postby kostik » Fri Jul 19, 2013 12:38 pm

So iam trying to rename about 100 hundred pictures in folder change_name

Code: Select all
import os
x = 0
array = os.listdir("c:/Users/Acer/Desktop/change_name/") # makes a list of files in change_name folder
for file in array:
    os.rename(file,file +str(x)) #here is problem...keep showing me errorFileNotFoundError: [WinError 2] : 'out0000.png0'....first argument os.rename should be real name of file,second - new name....i understand it in this way but maybe iam wrong
    x +=1
Last edited by kostik on Fri Jul 19, 2013 1:35 pm, edited 1 time in total.
Posts: 13
Joined: Tue Apr 16, 2013 10:26 am

Re: renaming files

Postby Yoriz » Fri Jul 19, 2013 1:01 pm

You didn't include a traceback of the error you are getting.

Here are some things to think about:
What does os.listdir return?
When loop array what is file?
When calling os.rename what does it expect the src & dst to be?
what are you actually calling os.rename with when you are doing os.rename(file,file +str(x))?
New Users, Read This
Join the #python-forum IRC channel on!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython, some Python 3.3
User avatar
Posts: 571
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Return to General Coding Help

Who is online

Users browsing this forum: 7stud, metulburr and 1 guest