<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def from_dir(cls, top, workdir=None, name=None, manager=None, max_depth=2):
 """ Find all flows located withing the directory `top` and build the `BatchLauncher`. Args: top: Top level directory or list of directories. workdir: Batch workdir. name: manager: :class:`TaskManager` object. If None, the manager is read from `manager.yml` In this case the YAML file must provide the entry `batch_manager` that defined the queue adapter used to submit the batch script. max_depth: Search in directory only if it is N or fewer levels below top """

        from .flows import Flow
        def find_pickles(dirtop):
            # Walk through each directory inside path and find the pickle database.
            paths = []
            for dirpath, dirnames, filenames in os.walk(dirtop):
                fnames = [f for f in filenames if f == Flow.PICKLE_FNAME]
                paths.extend([os.path.join(dirpath, f) for f in fnames])
            return paths

        if is_string(top):
            pickle_paths = find_pickles(top)
        else:
            # List of directories.
            pickle_paths = []
            for p in top:
                pickle_paths.extend(find_pickles(p))

        #workdir = os.path.join(top, "batch") if workdir is None else workdir
        workdir = "batch" if workdir is None else workdir
        new = cls(workdir, name=name, manager=manager)

        for path in pickle_paths:
            new.add_flow(path)

        return new