Possible to search/replace a character in all titles?
I've just imported a heap of entries from Papers3, and quite a few of the file titles have a { character in-front.
Is it possible to do some type of bulk search/replace, or regex to remove the "{" character if it is at the start of the file title?
https://i.imgur.com/iMTOzv4.png
Is it possible to do some type of bulk search/replace, or regex to remove the "{" character if it is at the start of the file title?
https://i.imgur.com/iMTOzv4.png
Then enable and open the Run JavaScript window:
https://www.zotero.org/support/dev/client_coding/javascript_api#running_ad_hoc_javascript_in_zotero
Then run this code to see the titles that would be affected:
var s = new Zotero.Search();
s.libraryID = Zotero.Libraries.userLibraryID;
s.addCondition('itemType', 'is', 'attachment');
s.addCondition('title', 'contains', '{');
var ids = await s.search();
if (!ids.length) {
return "No items found";
}
var titles = [];
for (let id of ids) {
let item = Zotero.Items.get(id);
let title = item.getField('title');
if (title.startsWith('{') && !title.includes('}')) {
titles.push(title);
}
}
return titles;
And run this code to fix them:
var s = new Zotero.Search();
s.libraryID = Zotero.Libraries.userLibraryID;
s.addCondition('itemType', 'is', 'attachment');
s.addCondition('title', 'contains', '{');
var ids = await s.search();
if (!ids.length) {
return "No items found";
}
for (let id of ids) {
let item = Zotero.Items.get(id);
let title = item.getField('title');
if (title.startsWith('{') && !title.includes('}')) {
item.setField('title', title.substr(1));
await item.saveTx();
}
}