Skip to content

Instantly share code, notes, and snippets.

@jakeoid
Last active June 1, 2020 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakeoid/875c617dcc9fb1d67e493e5c65a645db to your computer and use it in GitHub Desktop.
Save jakeoid/875c617dcc9fb1d67e493e5c65a645db to your computer and use it in GitHub Desktop.
This script renames files randomly, designed for https://random.birb.pw/

MIT License

Copyright (c) 2017 Jakeoid

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

# -*- coding: utf-8 -*-
# ┌┐ ┬┬─┐┌┐
# ├┴┐│├┬┘├┴┐
# └─┘┴┴└─└─┘
#
# RANDOM BIRB FILENAME
# :copyright: (c) 2017 Jakeoid
# :license: MIT, see LICENSE.md for details.
# Our Imports
import os
import random
# Our Directory
directory = "./"
# Our Looper
for filename in os.listdir(directory):
# See if our filename is of filetype .jpg or .jpeg.
# > FILETYPE .JPEG
if filename.endswith(".jpg") or filename.endswith(".jpeg"):
# Making a new filename with
newfilename = ''.join(random.choice('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
for n in range(5))
# Rename our file.
os.rename(filename, newfilename + ".jpg")
# Continue on.
continue
# > FILETYPE .GIF
elif filename.endswith(".gif"):
# Making a new filename with
newfilename = ''.join(random.choice('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
for n in range(5))
# Rename our file.
os.rename(filename, newfilename + ".gif")
# Continue on.
continue
# > FILETYPE .PNG
elif filename.endswith(".png"):
# Making a new filename with
newfilename = ''.join(random.choice('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
for n in range(5))
# Rename our file.
os.rename(filename, newfilename + ".png")
# Continue on.
continue
# > ANYTHING ELSE
else:
# Ignore and continue on.
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment