/* Albert Cardona 2007 This work is in the Public Domain. USE AT YOUR OWN RISK. */ import java.io.*; import ij.plugin.PlugIn; import ij.gui.GenericDialog; import ij.io.DirectoryChooser; import ij.IJ; /** The program takes: - a string with which to select a subset of files. - a string to look for in the subset of selected files. - a replacement string. If a file with the new name exists already, the renaming will not happen for that file and a warning is issued to the log window and the terminal. */ public class Rename_Files implements PlugIn { public void run(String arg) { DirectoryChooser dc = new DirectoryChooser("Select directory"); String dir = dc.getDirectory(); if (null == dir || dir.startsWith("null")) return; GenericDialog gd = new GenericDialog("Renamer"); gd.addMessage("Chosen dir:"); gd.addMessage(dir); gd.addStringField("File name contains: ", ""); gd.addStringField("Substring to replace: ", ""); gd.addStringField("Replacement substring: ", ""); gd.showDialog(); if (gd.wasCanceled()) return; // test: //IJ.log("_" + dir + "_\n_" + gd.getNextString() + "_\n_" + gd.getNextString() + "_\n_" + gd.getNextString() + "_"); main(new String[]{dir, gd.getNextString(), gd.getNextString(), gd.getNextString()}); } static public void main(String[] args) { if (args.length < 4) { p("Usage: java Rename_Files