Skip to contents

Lists non-trashed attachments with their parent, hash and the local file when it exists: imported files live under storage/<key>/ beside the database, linked files at their absolute path. Filter by the keys of attachments or of their parent records, or by MD5.

Usage

zotLocalFiles(
  keys = NULL,
  md5 = NULL,
  path = file.path(Sys.getenv("HOME"), "Zotero", "zotero.sqlite")
)

Arguments

keys

Optional character vector of attachment or parent item keys.

md5

Optional character vector of file hashes.

path

Database file; the storage directory is its sibling storage.

Value

A data.table with itemKey, parentKey, groupID, contentType, linkMode, md5 and file.

Details

The database may lag the Web API and a file may be absent locally even when the server holds it: a NA in file is an observation about this machine, not about the library. linkMode follows the client: 0 imported file, 1 imported URL, 2 linked file, 3 linked URL.

Examples

Path <- tempfile(fileext = ".sqlite")
Connection <- DBI::dbConnect(RSQLite::SQLite(), Path)
DBI::dbWriteTable(Connection, "libraries", data.frame(libraryID = 1L))
DBI::dbWriteTable(Connection, "groups",
                  data.frame(libraryID = integer(), groupID = integer()))
DBI::dbWriteTable(Connection, "items", data.frame(
  itemID = 1:2, key = c("PARENT", "FILE"), libraryID = 1L
))
DBI::dbWriteTable(Connection, "itemAttachments", data.frame(
  itemID = 2L, parentItemID = 1L, linkMode = 0L,
  contentType = "application/pdf", path = "storage:paper.pdf",
  storageHash = "abc"
))
DBI::dbWriteTable(Connection, "deletedItems", data.frame(itemID = integer()))
DBI::dbDisconnect(Connection)
zotLocalFiles(keys = "PARENT", path = Path)
#>    itemKey parentKey groupID     contentType linkMode    md5   file
#>     <char>    <char>   <int>          <char>    <int> <char> <char>
#> 1:    FILE    PARENT       0 application/pdf        0    abc   <NA>
unlink(Path)