BatchProcessFolders


SUBMITTED BY: smart4two

DATE: Jan. 1, 2018, 12:18 p.m.

FORMAT: Text only

SIZE: 1.3 kB

HITS: 173

  1. // "BatchProcessFolders"
  2. //
  3. // This macro batch processes all the files in a folder and any
  4. // subfolders in that folder. In this example, it runs the Subtract
  5. // Background command of TIFF files. For other kinds of processing,
  6. // edit the processFile() function at the end of this macro.
  7. requires("1.33s");
  8. dir = getDirectory("Choose a Directory ");
  9. setBatchMode(true);
  10. count = 0;
  11. countFiles(dir);
  12. n = 0;
  13. processFiles(dir);
  14. //print(count+" files processed");
  15. function countFiles(dir) {
  16. list = getFileList(dir);
  17. for (i=0; i<list.length; i++) {
  18. if (endsWith(list[i], "/"))
  19. countFiles(""+dir+list[i]);
  20. else
  21. count++;
  22. }
  23. }
  24. function processFiles(dir) {
  25. list = getFileList(dir);
  26. for (i=0; i<list.length; i++) {
  27. if (endsWith(list[i], "/"))
  28. processFiles(""+dir+list[i]);
  29. else {
  30. showProgress(n++, count);
  31. path = dir+list[i];
  32. processFile(path);
  33. }
  34. }
  35. }
  36. function processFile(path) {
  37. if (endsWith(path, ".tif")) {
  38. open(path);
  39. run("Subtract Background...", "rolling=50 white");
  40. save(path);
  41. close();
  42. }
  43. }

comments powered by Disqus