r/programmingrequests • • Apr 01 '17

[REQUEST] Bulk Rename Utility

Hi. I often rename a lot of files (.png specifically) and was wondering if there is a simple program out there that would let me just highlight them all and rename them to something simple like 001.png-999.png... Preferably have the option readily available by just right clicking on the highlighted files.

Something like this would be perfect for me: http://i.imgur.com/jHVAayO.png

Thanks in advanced

//Crim

3 Upvotes

13 comments sorted by

2

u/crimson4649 Apr 01 '17

updated first post with a mockup image of how i would like the program to be!

1

u/NoG5 Apr 02 '17

this is kinda a big request as making shell extensions is hard, a lot harder than it should be so might be fairly few that is able to do this here

2

u/ThatRedstoneGuy Apr 01 '17

Pm me. I can work on this asap

2

u/serg06 Apr 01 '17

I made it in python3. Just drag and drop all the files you want to rename right on top of the script.

Unfortunately it seems to be causing problems if you have python2 installed as well, since it launches from that instead of from python3, but it may still work.

Also it only works for Windows.

try:
    import sys
    from math import ceil, log10
    from os import rename

    file_paths = sys.argv[1:]
    #file_paths = ['C:\\repo\\bulk_renamer\\hello1.txt', 'C:\\repo\\bulk_renamer\\hello2.txt']

    length = len(file_paths)
    if length < 1:
        input("Drag files onto bulk_renamer.py to rename.")

    digits = int(ceil(log10(length+1)))

    for i, path in enumerate(file_paths):
        path = path.replace('\\', '\\\\')
        directory = '\\\\'.join(path.split('\\\\')[0:-1])
        new_name = str(i+1).zfill(digits)
        extension = ('.' + path.split('.')[-1]) if '.' in path else ''
        result = '%s\\\\%s' % (directory, new_name + extension)
        print(path, result)
        rename(path, new_name + extension)

except Exception as err:
    input("An error has occurred:\n%s\nPress enter to continue..." % err)

else:
    input("Done! Press enter to continue...")

2

u/crimson4649 Apr 01 '17

sorry i need something more simple and windows friendly.

3

u/serg06 Apr 01 '17

It is windows friendly.

2

u/ThatRedstoneGuy Apr 02 '17

Here's my attempt at this. Link You must drag the program into your "Send to" folder. Then, upon right-clicking with files selected it will say Send to... BulkRename.exe. This will process your files. It checks for whether it needs the 0.png, 00.png 000.png, etc automatically.

1

u/NoG5 Apr 03 '17

i decided to learn how to do windows shell extensions this is how far i have got currently, it seems to work ok GIF Demo but i guess you probably don't really a third solution :P

1

u/crimson4649 Apr 03 '17

looks really good so far.

1

u/NoG5 Apr 03 '17

well you can give it a try if you want Download i made a install and uninstall bat files just run those and it should install/uninstall it, it will ask for UAC and restart explorer

disclaimer: i haven't tested it much and it's running in the shell so may be a bit unsafe :P