requires("1.46c") /* Macro randomizes the file names of all files in the selected direcotry - the selected directory must only contain image files - randomized files will be stored in a subfolder - in the original folder a file "randomizelist.txt" will be created that contains a two column list with newname and originalname Martin Hoehne feb 2012 _file_randomizer_v09 */ run("Bio-Formats Macro Extensions"); //This will enable the bioformats macro functions; needed for zvi files print("\\Clear"); //clear the log source_dir = getDirectory("Source Directory"); setBatchMode(true); list = getFileList(source_dir); //list is already an array File.makeDirectory(source_dir+File.separator+"randomized"); // new directory for Data zufallliste=newArray(0); // this array will be filled with the randomized file names for (i=0; i 99999) { do { zufall=zufall/10; } while zufall>99999; } zufallliste=Array.concat(zufallliste, zufall); //zufallliste is an array containing the randomized file names // open an image Ext.openImagePlus(source_dir + "/" + list[i]); // delete the original filename info from the metadata (displayed in the image header in imageJ) setMetadata("Label", "randomized_filename"); // save the file with the randomized filename (will later be renamed) saveAs("tiff", source_dir+File.separator+"randomized"+File.separator+zufall+".tif"); ; close(); } // rename the randomized files with a shorter finalname (1,2,3....) --better readable than the long random names // the random names (5 digit numbers) are sorted, and after sorting they [alphabetically because it is a string] smallest name // (number) is changed to 1, the second to 2 .... // since all randomnames are 5 digit numbers, the alphabetically sorting has the same result as sorting according to the number. // "decipher table": create an array with randomnames and originalnames fused into one string (and "random__" in between) bothnames=newArray(list.length); for (i=0; i