This is an old revision of the document!
File Renaming
Zotero automatically renames PDFs and other files saved to your library based on the bibliographic details of the parent item (title, author, etc.), freeing you from having to sort through piles of randomly named files or manually rename each new file to your preferred format.
Renaming Behavior
Zotero always renames files saved from the web (via the Zotero Connector, Add Item by Identifier, or Find Available PDF).
By default, Zotero will also rename stored PDFs and EPUBs that you add as to items as the first child attachment as well as files for which it successfully retrieves metadata. You can disable this by unchecking “Automatically rename attachment files using parent metadata” in the General pane of the Zotero settings. If an item already has an attachment, additional files will not be automatically renamed, so as to avoid changing the filenames of supplementary materials.
Linked files are not automatically renamed by default, but you can enable “Rename linked files” from the General pane of the Zotero settings to apply renaming to those as well.
You can adjust which file types Zotero automatically renames via the extensions.zotero.autoRenameFiles.fileTypes
hidden pref.
Attachment Title vs. Filename
Attachments have two separate names: the attachment title shown in the items list and the filename of the file on disk.
The file on disk is automatically renamed based on parent item metadata such as the title and authors, as explained above. Since the parent item row in the items list already displays that metadata, Zotero doesn't show the filename directly in the items list. Instead, it uses simpler attachment titles such as “PDF” or “Ebook” for the first file of a given type or includes additional information about the source of the file (e.g., “ScienceDirect Full Text PDF” for a file saved from ScienceDirect, or “Accepted Version” or “Submitted Version” for open-access files). These separate titles avoid cluttering the items list with duplicate metadata and prevent parent items from being unnecessarily expanded when searching for titles or creators.
Subsequent files added to an item from the filesystem will still get titles named after the filename (without the file extension), since those are likely to be supplementary files and the filename may be informative.
You can view and change the title and filename by clicking on the attachment and looking in the item pane.
Attachment Title Handling in Zotero 7
Zotero 7 makes a couple changes to how attachment titles are handled:
- Prior to Zotero 7, the attachment title was unnecessarily changed to the filename when manually running Rename File from Parent Metadata. This was a bug that led many people to believe that files weren't automatically renamed and it was necessary to run Rename File from Parent Metadata on every new attachment. The title is no longer changed, and titles remain as “PDF”, “ScienceDirect Full Text PDF”, or whatever they were set to previously.
- When dragging a file from the filesystem or creating a parent item, Zotero now sets the title of the first attachment of a given type to “PDF”, “EPUB”, etc., instead of setting the title based on the filename.
People who were unnecessarily running Rename File from Parent Metadata on every attachment or who were using the ZotFile plugin (which also set the title to the filename) might be used to seeing filenames in the items list, but we'd encourage people to give the new behavior a try.
If you'd like to convert existing attachments to use “PDF” titles for consistency, you can select all items in the items list, go to Tools → Developer → Run JavaScript, and run this code:
var items = ZoteroPane.getSelectedItems(); for (let item of items) { if (!item.isRegularItem()) continue; let attachment = await item.getBestAttachment(); if (!attachment) continue; let title = attachment.getField('title'); if (title.endsWith('.pdf')) { attachment.setField('title', 'PDF'); await attachment.saveTx(); } }
This will go through the primary attachment of every selected item and convert the title of any that ends in “.pdf” to just “PDF”.
You should test with a smaller number of selected items first to make sure it's doing what you expect.
Customizing the Filename Format
By default, Zotero names files after the parent item's creator (1–2 authors or editors), year, and title:
Lee et al. - 2023 - The First Room-Temperature Ambient-Pressure Superconductor.pdf
While Zotero has always renamed files automatically, Zotero 7, currently in beta, introduces a new, powerful syntax for customizing filenames. The default format can be customized from the General pane of the Zotero settings.
This is the default template string:
{{ firstCreator suffix=" - " }}{{ year suffix=" - " }}{{ title truncate="100" }}
The following variables and parameters are supported:
Variables
Variable | Description |
---|---|
authors | Parent item's principal creators (depending on the item type these are authors or artists but not editors or other contributors). |
editors | Parent item's editors. |
creators | All parent item's creators. |
firstCreator | Parent item's creator (1–2 authors or editors). |
itemType | Parent item type. |
attachmentTitle | The title of the attachment that is being renamed or created |
year | Year, extracted from parent item's date field. |
Any item field | Complete list of fields can be found at the bottom of this page. |
If a variable value starts or ends with a space, which is likely to happen when used in conjunction with the
truncate
parameter, these spaces are removed from the filename.
Parameters
Parameter | Variables | Default Value | Description |
---|---|---|---|
start | All | Truncates the variable value from the beginning. For example, {{ title start="5" }} will be replaced with the value of the parent item's title, omitting the first 5 characters. It can be combined with truncate . |
|
truncate | All | Truncates variable value at fixed number of characters, e.g, {{ title truncate="20" }} will be replaced with the first 20 characters of parent item's title. Truncation happens after every other parameter has been applied, except for prefix , suffix and case . |
|
prefix | All | Prepends variable with given character(s), e.g., {{ title prefix="title" }} will be replaced by the word “title” followed by parent item's title. If variable is empty (e.g., item's parent has empty title), entire statement, including prefix, is ignored. |
|
suffix | All | Appends given character(s) at the end of a variable with, e.g., {{ title suffix="!" }} will be replaced by parent item's title followed by an exclamation mark. If variable is empty (e.g., item's parent has empty title), entire statement, including suffix, is ignored. |
|
case | All | Converts case of a variable, following values are accepted: upper , lower , sentence , title , hyphen , snake , camel . E.g., {{ title case="snake" }} will result in title_written_like_this in the file name. |
|
replaceFrom | All | Use a regular expression to replace a matching string in the variable with a value specified by the replaceTo parameter. For example, {{ title replaceFrom="problem" replaceTo="solution" }} is substituted with the parent item's title where the first occurrence of the word “problem” is replaced with the word “solution”. It can be further configured with regexOpts parameter. |
|
replaceTo | All | Defines a replacement value to use when matching using regular expressions (see replaceFrom ). It is possible to specify capture groups defined in replaceFrom . For example, to prefix all occurrences of the words “dog” and “cat” with the word “super-” in the item's title, the following template can be used: {{ title replaceFrom="(dog|cat)" replaceTo="super-$1" regexOpts="gi" }} . |
|
regexOpts | All | 'i' | Defines flags to use when matching using regular expressions (see replaceFrom ). For example, {{ title replaceFrom="\s+" regexOpts="g" }} is substituted with the parent item's title with all white space removed (without regexOpts , only the first white space would be removed). |
match | All | Use a regular expression to test for a matching string in the variable. This parameter is useful in conditions and it cannot be used with any other parameters, except for regexOpts . For example, the following template will only return the parent item's URL if the URL's domain name is zotero.org: {{ if {{ url match="^https?://zotero.org.*?$" }} }}{{ url }}{{ endif }} . |
|
max | authors , editors , creators | Limits number of creators to use, e.g., {{ editors max="1" }} will be replaced with first editor of parent's item. It can be configured with regexOpts parameter. |
|
name | authors , editors , creators | family | Customizes how creator name appears in the filename, with the following accepted options: family-given will use full name of the creator, beginning with family (last) name of the creator, given-family also uses full name but inverts the order, and options given and family will only use part of the parent item's creator's name. |
name-part-separator | authors , editors , creators | (single space character) | Defines what characters to use to separate given and family name, especially useful when combined with initialize . |
join | authors , editors , creators | , | Defines what characters to use to separate consecutive creators. |
initialize | authors , editors , creators | Enables use of initials for part or whole of creators name, with the following accepted options: full will use initials for the entire name, given and family will only use initials for that part of the name. Order of name parts is controlled by name parameter and only parts included by name parameter can be converted to initials. E.g. {{ authors name="given-family" initialize="given" }} will be replaced by a comma-separated list of authors, where each author's given name is replaced with an initial, followed by a dot and a space (e.g. J. Smith, D. Jones ). |
|
initialize-with | authors , editors , creators | . | Controls what character is appended to the initial, if name part was initialized. |
localize | itemType | Whether to use localized value of the item type variable, e.g., {{ itemType localize="true" }} will be replaced by parent item's type spelled in the language Zotero is using. |
Examples
A year of publication, followed by a hyphen-separated list of authors, followed by a title truncated at 30 characters:
Template: {{ year suffix="-" }}{{ authors name="family-given" initialize="given" initialize="-" join="-" suffix="-" case="hyphen" }}{{ title truncate="30" case="hyphen" }}
Filename: 2023-lee-sukbae-kim-ji-hoon-kwon-young-wan-the-first-room-temperature-amb.pdf
Anything not included inside a {{
bracket is copied to the filename literally:
Template: {{ itemType localize="true" }} from {{ year }} by {{ authors max="1" name="given-family" initialize="given" }}
Filename: Preprint from 2023 by S. Lee.pdf
Templates also support conditionals. Certain part of the template can be included or excluded using a combination of if
, elseif
, and else
. The condition must end with endif
. The template below will use the DOI for journal articles and preprints, the ISBN for books, and the title for any other item type:
{{ if itemType == "book" }} {{ISBN}} {{ elseif itemType == "preprint" }} {{ DOI }} {{ elseif itemType == "journalArticle" }} {{ DOI }} {{ else }} {{ title }} {{ endif }}
It's possible to use regular expressions to match values and change the behavior of the template. For example, the following template preserves common attachment names (such as “Full Text”), but for attachments with non-matching titles, it uses the standard Zotero filename template:
{{ if {{ attachmentTitle match="^(full.*|submitted.*|accepted.*)$" }} }} {{ attachmentTitle }} {{ else }} {{ firstCreator suffix=" - " }}{{ year suffix=" - " }}{{ title truncate="100" }} {{ endif }}
Complete List of Fields
abstractNote
accessDate
applicationNumber
archive
archiveID
archiveLocation
artworkMedium
artworkSize
assignee
audioFileType
audioRecordingFormat
billNumber
blogTitle
bookTitle
callNumber
caseName
citationKey
code
codeNumber
codePages
codeVolume
committee
company
conferenceName
country
court
date
dateDecided
dateEnacted
dictionaryTitle
distributor
docketNumber
documentNumber
DOI
edition
encyclopediaTitle
episodeNumber
extra
filingDate
firstPage
format
forumTitle
genre
history
identifier
institution
interviewMedium
ISBN
ISSN
issue
issueDate
issuingAuthority
journalAbbreviation
label
language
legalStatus
legislativeBody
letterType
libraryCatalog
manuscriptType
mapType
meetingName
nameOfAct
network
numPages
number
numberOfVolumes
organization
pages
patentNumber
place
postType
presentationType
priorityNumbers
proceedingsTitle
programTitle
programmingLanguage
publicLawNumber
publicationTitle
publisher
references
reportNumber
reportType
reporter
reporterVolume
repository
repositoryLocation
rights
runningTime
scale
section
series
seriesNumber
seriesText
seriesTitle
session
shortTitle
status
studio
subject
system
thesisType
title
type
university
url
versionNumber
videoRecordingFormat
volume
websiteTitle
websiteType