Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive search not working properly #141

Open
CommunyAS opened this issue Oct 25, 2024 · 1 comment
Open

Recursive search not working properly #141

CommunyAS opened this issue Oct 25, 2024 · 1 comment

Comments

@CommunyAS
Copy link

It seems that the recursive search function is not working properly.

When setting the search folder to a folder two (or more) levels higher in the hierarchy (i.e. to main_folder in a hierarchy main_folder > sub_folder > literature_notes), the plugin does not find any notes (although existing).

When setting the search folder to a folder one level in the hierarchy (i.e. sub_folder in a hierarchy as above) or the folder containing MD notes (i.e. literature_notes) is works.

@daeh
Copy link
Owner

daeh commented Oct 25, 2024

Please report your versions (OS, Zotero, MDBC)

Upload your debugging logs (Tools > MarkDB-Connect Troubleshooting > Save Full Debugging Logs)

If you want to troubleshoot on your end, you can run this from Tools > Developer > Run JavaScript to see what files MDBC is finding

const listDirContents = async (dirpath) => {
  const items = []
  await Zotero.File.iterateDirectory(dirpath, (item) => {
    if (!item.name.startsWith('.')) {
      items.push(item)
    }
  })
  return items
}

const listFilesRecursively = async function* (dirpath) {
  // Does not follow symbolic links //
  const entries = await listDirContents(dirpath)
  for (const entry of entries) {
    const zfile = Zotero.File.pathToFile(entry.path)
    if (zfile.isReadable() && !zfile.isHidden() && !zfile.isSpecial() && !zfile.isSymlink()) {
      if (zfile.isDirectory()) {
        yield* listFilesRecursively(entry.path)
      } else if (zfile.isFile()) {
        yield entry
      }
    }
  }
}

const files = []
for await (const file of listFilesRecursively("YOUR-LOCAL-PATH-TO/main_folder")) {
  files.push(file)
}

return files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants