Zotfile setup - Find all stored (not linked) attachments
Hello! I'm using Zotero with Zotfile to manage my linked attachments, which are stored in a folder that syncs with my OneDrive.
Everything works fine whenever I add an item to Zotero through the journal webpage. However, whenever I add a PDF directly, it gets stored in Zotero storage and does not get automatically moved and renamed by Zotfile. I understand this is expected behaviour.
I can then manually moved them by right clicking an item and choosing "Rename Attachments". That also works. But in the middle of a research session, it's natural that sometimes I miss some (because it opens the pdf in the browser directly), and I get some attachments stored in Zotero Storage while others are in the folder on OneDrive.
Is there any way I can search for "Stored Files" or "Non-linked files" on Zotero so I can periodically go through them and manually run Zotfile on them?
Everything works fine whenever I add an item to Zotero through the journal webpage. However, whenever I add a PDF directly, it gets stored in Zotero storage and does not get automatically moved and renamed by Zotfile. I understand this is expected behaviour.
I can then manually moved them by right clicking an item and choosing "Rename Attachments". That also works. But in the middle of a research session, it's natural that sometimes I miss some (because it opens the pdf in the browser directly), and I get some attachments stored in Zotero Storage while others are in the folder on OneDrive.
Is there any way I can search for "Stored Files" or "Non-linked files" on Zotero so I can periodically go through them and manually run Zotfile on them?
(1) Use your OS's file search routine to find any PDFs under the Zotero\Storage hierarchy.
(2) I use FreeFileSync (Windows app) for backups. It shows me all new files under Zotero\Storage since the last backup. So it's easy to see any new stray PDFs that haven't been moved yet.
I sometimes end up wanting to make sure a set of items is all on zotero storage (tricky to switch from linked to local, but that's another story), and without this it's necessary just to try moving all of them to be sure, or select one by one.
var sql = "SELECT (? || '\\storage\\' || key || REPLACE(path,'storage:','\\')) AS filepathnames FROM itemAttachments JOIN items USING (itemID) WHERE libraryID=1 AND path IS NOT NULL AND path LIKE ? ORDER BY filepathnames";
var filepathnames = await Zotero.DB.columnQueryAsync(
sql,
[
Zotero.DataDirectory.dir,
'storage:%.pdf'
]
);
return filepathnames.join('\n');
Once the list tells you which local PDFs you have omitted to move to your linked folder (Zotfile's Custom Location), you would have to initiate those file moves manually. My javascript/Zotero skills unfortunately aren't up to automating those PDF file moves directly from the list, and then updating Zotero's record of the attached PDF location.
Doing it manually within Zotero, the first issue is figuring out from each local PDF file path in the list which item the PDF belongs to. But if you had PDF file auto-renaming when the file was stored, that should be easy to tell from the PDF title. Then of course you can move each file individually in Zotero by selecting its item (or Ctrl-click to select more than one at a time), and then selecting Zotfile's Manage Attachments\Rename and Move. Depending on the number of files involved, that could still be a big job. But you probably already knew that !
On my two machines, I have Zotero linking to attachments in a folder on D:\. But for one of these machines, the D:\ path is a symlink to S:\. And apparently I mistakenly on one machine I moved some files and then linked to them as in S:\, so those links are now broken on the machine where I don't have an S:\.
Thanks so much for any thoughts you may have!
var filepathnames = await Zotero.DB.columnQueryAsync('SELECT path AS filepathnames FROM itemAttachments WHERE path LIKE ? ORDER BY path','S:%');
return filepathnames.join('\n');
The list may also include missing attachments - that is attachment files that Zotero thinks are in the linked location folder but are not still there.
The list will not include 'orphans' - that is, any attachment files in the linked folder location that Zotero no longer has a record of.