ImageJ (Fiji) search directory for a given file, using python with imageJ macro

172 Views Asked by At

I have a python class that I want to use with an imageJ macro. The python class(below) will walk(search) a directory and look for multiple files given by the user. I need to use this logic with an ImageJ macro to walk a directory and return a list with references to the files I need. Is there a way I can use this class with an imageJ macro or somehow recreate this within the imageJ macro?

import sys, os
from fnmatch import fnmatch

def searchDirectory():
    root = "\home"
    fileNames = ["test.txt", "plshelp.cpp"]
    resultPaths = []

    for path, subdirs, files in os.walk(root):
      for name in files:
        for target in fileNames:
          if fnmatch(name, target):
            if checkMatches(name, resultPaths):
              resultPaths.append(os.path.join(name))

    return resultPaths


def checkMatches(name, targets):
    flag = True

    for target in targets:
      if fnmatch(name, target):
        flag = False

    return flag
0

There are 0 best solutions below