Thursday, April 16, 2015

linux - How can I rename all image files within a directory (and recursively within its subdirectories)?

I have a directory containing a large number of image files, some of which are in subdirectories. I need to rename all image files matching *.png, *.jpg, *.jpeg, *.bmp, *.gif using a simple pattern for renaming:



  • the same prefix for all files;

  • a number with padding zeros and printed as hex string.


My goal is to assign a unique name to all image files, independently of their extension, so that I can then convert them to the same image format without the risk of overwriting those files with the same names.


I was writing a script in order to perform the above procedure (for directory listing, I was inspired by the code snippet of this answer).


for root, dirs, filenames in os.walk(path):
for filename in filenames:
if filename.endswith((".jpeg", ".jpg", ".png", ".gif", ".bmp")):
# rename file

I was wondering if there was any bash or powershell command in order to perform the above procedure.

No comments:

Post a Comment