Feature request: allow multiple bibtex/ris files to be selected for import

When importing items from bib files, I am unable to select multiple files to be imported sequentially. This would be fantastic, since I have numerous (i.e. dozens) of bib files that need to be imported as their own collections. This currently requires multiple user actions, and I don't see why this is truly necessary.
  • You can just cat *.bib > combined.bibtex (Mac, Linux) or type *.bib > combined.bibtex (Windows), then import the combined file.
  • That won’t put the items from each BibTeX file into their own collections though.
  • That is true. It could be done through the javascript console.
  • Yes, keeping the contents of each bib file in their own collections is key. emilianoeheyns, can you describe in a bit more detail what this might entail, or point me to a more informative resource about this?
  • You can either through https://www.zotero.org/support/dev/client_coding/javascript_api or https://github.com/retorquere/zotero-better-bibtex/tree/master/test/fixtures/debug-bridge run your own javascripts insize Zotero.

    The script would look something like
    const bibfiles = [
    'absolute path to.bib',
    'absolute path to other.bib',
    ];

    for (const bibfile of bibfiles) {
    const file = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile)
    file.initWithPath(bibfile)

    await Zotero_File_Interface.importFile({ file, createNewCollection: true })
    }
    making sure to check the async checkbox if you're using the first option.
  • Thank you. This is extremely helpful. I will provide an update later on once I develop a more exact script that resolves this issue.
  • edited 13 days ago
    Simpler version:

    var bibfiles = [
    'absolute path to.bib',
    'absolute path to other.bib',
    ];
    for (let file of bibfiles) {
    await Zotero_File_Interface.importFile({ file, createNewCollection: true });
    }


    (You also don't ever really need to check the "async" checkbox manually — that's checked automatically when there's an "await" in the code.)
  • edited 13 days ago
    Thanks, the simplified version worked like a charm. I did get a `===>undefined<=== (undefined)` returned at the end though, probably due to the trailing comma at the end of the bibfiles array, but it was inconsequential.
  • That's expected, and not due to the comma — it displays the return value for async code, and there's no return value here, so the return value is undefined.
Sign In or Register to comment.