batch move PDF files out of reference items to the top level
I imported many PDF files from another program. The meta information was not extracted from these PDF files probably by the other program, and now what I have in Zotero is like this:
<<pdf_file_1.pdf>>
---pdf_file_1
<<pdf_file_2.pdf>>
---pdf_file_2
<<pdf_file_3.pdf>>
---pdf_file_3
Basically the only meta information is the title of the PDF files.
I want to move these PDF files out of the reference items to the top level, so that the meta information can be extracted. Manually dragging individual files is tedious. I wonder if there are any automatic method to achieve this.
Thanks.
<<pdf_file_1.pdf>>
---pdf_file_1
<<pdf_file_2.pdf>>
---pdf_file_2
<<pdf_file_3.pdf>>
---pdf_file_3
Basically the only meta information is the title of the PDF files.
I want to move these PDF files out of the reference items to the top level, so that the meta information can be extracted. Manually dragging individual files is tedious. I wonder if there are any automatic method to achieve this.
Thanks.
await Zotero.DB.executeTransaction(async function () {
var items = ZoteroPane.getSelectedItems();
for (let item of items) {
if (!item.isRegularItem()) continue;
let attachment = await item.getBestAttachment();
attachment.parentID = null;
await attachment.save();
item.deleted = true;
await item.save();
}
});
This will turn all the primary child attachments of the selected items into top-level items and move the selected parent items to the trash. It won't handle child notes or other child attachments.
You should temporarily disable auto-syncing and make a backup of zotero.sqlite in your data directory before running this, and make sure it did what you want before re-enabling syncing.
Thanks for your reply. Your JavaScript solution works great.
Another question: when I dragged a PDF file to an item from the center panel, the PDF file appears inside that item as a child item, but a copy of the PDF file still remains in the center panel. If I delete the PDF file in the center panel, the PDF inside the item (the child item) is also deleted. It seems that they are linked.
How to move a PDF file in the center panel into an item?