Re: Batch File Rename(JPEG) macro?
Posted by
jmutterer on
URL: http://imagej.273.s1.nabble.com/Batch-File-Rename-JPEG-macro-tp3694281p3694283.html
Zack,
the following macro does what you explained.
// batch rename jpgs
dir = getDirectory('Choose Directory ');
list = getFileList(dir);
n=1000;
for (i=0; i<list.length; i++) {
if (endsWith(toLowerCase(list[i]),".jpg")) {
newpath = dir+n+".jpg";
if (!File.exists(newpath)) { done = File.rename(dir+list[i],newpath); }
else { print("error: "+newpath); }
n++;
}
}
// end
Jerome.
On Tue, Dec 9, 2008 at 6:03 PM, Miguel A. de Pedro <
[hidden email]>wrote:
> Hi Zack,
>
> This is probably not exactly what you want, but you can do something very
> close in Windows (if you are PC) with the file>rename command. Select all
> files in the folder, leaving the cursor in the file you want to be the
> first,click right mouse button, select rename and enter the common
> characters you want for all the files, then click enter and you end up
> with a series of files with the common name (or number) name and a serial
> numeral in parenthesis.
>
> All the best
>
> Miguel
>
> Does anyone know of a quick macro that will rename all files(just jpegs)
> > in
> > a folder, in a sequence? The only condition is I want to specify the
> name
> > of the first file in the list. That name will always be a number(for
> > example, 1000.jpg) Then I want them to be named 1001.jpg, 1002.jpg, etc.
> > until everything has been renamed.
> >
> > My code writing ability is pretty poor, and now I'm just trying to cut
> and
> > paste from other sources, but I can't find anything too similar.
> >
> > Thanks!
> > -zack
> >
>