path = File.openDialog("Select a file"); open(path); setBatchMode(true); dir = File.getParent(path); name = File.getName(path); folderName = split(name, "."); folderPath = dir + "/" + folderName[0]; File.makeDirectory(folderPath); for (i=1; i<=nSlices; i++) { saveAs("Text Image", folderPath + "/Slice_" + pad(i) + ".txt"); run("Next Slice [>]"); } function pad(n) { n = toString(n); while (lengthOf(n)<5) n = "0"+n; return n; }