Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Suppose I had about 500 .JPG and .jpg files in my folder "c:\images\". How to ask Mathematica to load all the .jpg and .JPG file names then make a case insensitive sorted list out of them, say {"butterfly.jpg", "Fish.jpg", "marilyn.jpg", "Rabbit.JPG"... }, and finally rename the files in the folder as:

enter image description here

fnameLst = FileNameTake/@ 
 FileNames[{"*.jpg", "*.JPG", "*.jpeg", "*.JPEG"}, "c:\\images", Infinity]
share|improve this question
up vote 7 down vote accepted

This should do the trick.

(*Import file names and generate output names*)
folder = "C:\\images\\";
fnameLst = Sort[FileNameTake /@ FileNames[{"*.jpg", "*.JPG", "*.jpeg", "*.JPEG"}, folder, 
fnameNewLst = "img_" <> IntegerString[#, 10, 3] <> ".jpg" & /@ Range[Length@fnameLst];

(*Rename files*)
RenameFile[folder <> #[[1]], folder <> #[[2]]] & /@ Transpose[{fnameLst, fnameNewLst}]
share|improve this answer
The built-in IntegerString will do what your NumberPad is doing. – wxffles Sep 4 '14 at 2:17
Thanks, I didn't know about IntegerString. I'll edit my answer. – paw Sep 4 '14 at 2:19
paw, I see room for what I feel are improvements to this (good) answer. May I edit your post or would you prefer that I post separately? – Mr.Wizard Sep 24 '14 at 6:45
Feel free to edit my post senpai. Every edit that improves an answer is welcome, isn't this the philosophy of SE? – paw Sep 24 '14 at 14:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.