Recommended Posts

I have a folder, lets call it BASE in BASE we have about 200 folders of random names. In each of these folders contain a file called XXXXXX1.gif where XXXXXX is a random set of charcters. I want to rename every XXXXXX1.gif to XXXXXX.gif

I know windows has a rename command, but how do i go about setting up the parameters... i cant figure it out.

Help Please!

Thanks

Link to post
Share on other sites

I am guessing you mean like a batch script, batch makes me want to pull my hair out, so I wrote one in python. i am not exacty sure if this is what you need, but my script will do this. If you run the script from inside the folder "BASE" it will change any .gif file found in each of the sub folders to the name you specify in the variable "new_name". Warning . If you have more then one gif per folder it delete all but that last gif.

you will need to install python to run the script

#!/usr/bin/env python
import os

# enter the new name you want your gifs changed to below
new_name = "enter-name-here.gif"

for i in os.listdir(os.getcwd()):
directory = os.path.abspath(i)
if os.path.isdir(directory):
for file in os.listdir(directory):
if file.endswith(".gif"):
old_file = "%s/%s" %(directory, file)
new_file = "%s/%s" %(directory, new_name)
os.rename(old_file, new_file)

I was not sure if you had more then one gif file per folder, if you need something different then this, let me know, then i can change the script.

edit added later//

I tested it, and it seems to work correctly, if you do decide to use it, I would reccomend making a backup of the directory BASE, just in case it misbehaves

Edited by shanenin
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...