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))?
Due to the reasons discussed here we will be moving to on October 1 2016
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
Posts: 1672
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 8 guests