Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

1 Answer 1

up vote 5 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, 
     Infinity]];
fnameNewLst = "img_" <> IntegerString[#, 10, 3] <> ".jpg" & /@ Range[Length@fnameLst];

(*Rename files*)
RenameFile[folder <> #[[1]], folder <> #[[2]]] & /@ Transpose[{fnameLst, fnameNewLst}]
share|improve this answer
1  
The built-in IntegerString will do what your NumberPad is doing. –  wxffles Sep 4 at 2:17
    
Thanks, I didn't know about IntegerString. I'll edit my answer. –  paw Sep 4 at 2:19

Your Answer

 
discard

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.