Sort by filename?

I am new to Zotero and want to see if this program is suitable for me. I have an archive of thousands of sources ordered by subject and the files are named "date author subject" (e.g. 2005 Jones interviewing techniques). So far, about half are recognized and renamed by Zotero because many are scanned newspaper articles or books, many not in English. Of those, half are incorrectly recognized and usually miss important data, for example, only showing the title which is wrong.

This wouldn't be so bad if I could easily see my old file names as a sorting field, because then I could identify the file. But in the field chooser, "file" is not among the display options. I imagine this would be an easy thing to implement, but it doesn't seem present.

Am I missing something?

This tiny issue is probably a dealbreaker for me, since it makes this otherwise excellent program hard to use.
  • edited November 7, 2019
    If the files are already renamed, you can't get the old filenames, but you can temporarily turn off "Automatically rename attachment files using parent metadata" and add the files again. Once all the parent metadata is set correctly — either automatically or manually — you can select all the files using a search (e.g., create a saved search for [Attachment File Type] [is] [pdf] and then do Select All) and rename them all based on the parent metadata.

    If you haven't made any changes you need to keep and want to start from scratch with that option disabled, the cleanest way is to close Zotero and just delete the Zotero data directory.
  • Thanks for the quick reply. I found the switch to turn auto-rename off and that seems to work fine. My main problem is the fact I can't see the file names in the main directory, which is very important for me to find anything as Zotero's new titles are often gobbledygook.

    If I could somehow copy the filename to a different field that *can* be displayed that I never use, for example "edition" or "court" I could use that as a first column to display. I have no idea how to do this though.

  • You can click an item and press + on the keyboard to expand all parent items, which will reveal the attachment items underneath. For files added from disk, the attachment item title will initially be the same as the filename.
  • edited November 11, 2019
    Thanks, that helped! Now I can see what the file is about when Zotero misinterpreted the information. Now I just would like to be able to have "file name" as a column so I can sort by file name (which always starts with the publication date) - I'll make a separate post about that. Thanks again.
  • edited November 11, 2019
    If you need the publication date, you can just add the Date or Year column. We're unlikely to add a filename column, since that wouldn't apply to any top-level items.
  • I wish I could show you a screenshot, because less than half of my sources have filled in information, and from the ones that are filled in only about half have the date field filled in, while all the file names have the correct date. But those are sometimes hidden when converted.
  • Right, but we already went over above how to expand all items to show the filenames so that you can populate the Date field correctly, and after that you wouldn't have any need for the filenames.
  • (You can upload screenshots to any file-sharing service (e.g., Dropbox) and post links here.)
  • Thanks again for your input. It's going to be too much data entry work to fill in the blanks in my thousands of sources. Just wanted to be able to sort my files like I normally see them in windows.
  • If you want to remove the wrong parent metadata, you could do this:

    A. Separate pdf attachments from parent items:

    1. Add items with bad parent metadata to a collection, e.g., "FixParentMeta"

    2. Quick search ("All Fields & Tags"): .pdf

    3. Click at one item in the middle/central pane

    4. Edit -> Select All (or Ctrl+A): This selects only pdf attachments

    5. Drag all pdf attachments away from the parent items; clear the quick search field

    B. Delete bad parent items without attachments

    C. Create new parent items from attachments:

    1. Select all pdf files

    2. Right click -> "Create Parent Item"

    The new parent items have the file name in their title field.
  • @eversdavid: If you want to keep the extracted titles, I can write you a short script you can run within Zotero to set the Date field to the year in the child attachment title.
  • @qqbb that method seems to work well. Sorting by filename would have done the trick too, but in lieu of that, this workaround is much appreciated.

    @dstillman that would be fantastic! Please let me know how to run such a script, as I'm a novice at this.

    By the way, I'm very thankful for the rapid and helpful responses to my post. I think this has created a new Zotero convert. Look forward to working with this software!
  • I can write you a script, but it's sort of mutually exclusive with what @qqbb suggests, since the whole point of that workaround is to basically not use Zotero's metadata fields. So if you've done that, I'm not sure it's worth bothering.
  • the whole point of that workaround is to basically not use Zotero's metadata fields
    For me, creating parent items from filenames is usually followed by filling in the metadata fields manually. A script with regular expressions that moves e.g. the year to its metadata field could be very useful. This could use the title field in case parent items have already been created.

    I could also imagine that a script that allows changing the itemType of many items at once could be very useful in @eversdavid 's case with thousands of items to be edited, such that e.g. newspaper articles are easily recognizable. The Zutilo batch editing tools don't seem to do this.
  • For me, creating parent items from filenames is usually followed by filling in the metadata fields manually.
    Sure, but in this case the filenames don't even have the title, so the only way to have any chance of getting it automatically would be from the PDF extraction. By creating parent items named after the filename, @eversdavid would've overwritten those titles, at which point it's not clear that real metadata is a priority.
  • If a script could be written which takes the first 4 characters from the filename (or title, once I've done @qqbb's trick) and writes that into the date field, it would help immensely, because I could then sort by that field and get a good overview of my sources.
  • Again, though, if you follow qqbb's suggestion, you'll lose all the extracted titles, so I would recommend not doing that.
  • I'm only replacing titles with filenames when Zotero hasn't extracted anything correctly or useful as a title.
  • OK, first close Zotero and make a backup of the zotero.sqlite file in your Zotero data directory.

    Then reopen Zotero, go to Tools → Developer → Run JavaScript, and paste in and run this code:

    var s = new Zotero.Search();
    s.addCondition('libraryID', 'is', Zotero.Libraries.userLibraryID);
    s.addCondition('itemType', 'is', 'attachment');
    var ids = await
    for (let id of ids) {
    let item = Zotero.Items.get(id);
    let parentItemID = item.parentItemID;
    if (!parentItemID) {
    let parentItem = Zotero.Items.get(parentItemID);
    let title = item.getField('title');
    if (parentItem.getField('date') !== '') {
    if (title.match(/^[0-9]{4}( |$)/)) {
    let year = title.substr(0, 4);
    parentItem.setField('date', year);
    await parentItem.saveTx();

    This will add the year from every child attachment to the parent item if the parent item doesn't already have a value in its Date field.
Sign In or Register to comment.