Rename Your PDFs, and update zotero too!! (with python)

Hi all,

This script does the following :
- Rename all physical files in zotero storage to LastName - (Year) - Title
- Rename move paths in zotero database to meet new file names
- Rename attachment names in zotero to be Year - Journal

I have created a rename script in python to rename all journal articles in the database based on select entries from the reference. Currently it renames each file in the filesystem as

Author_lastName (Year) Title truncated after 25 chars...pdf

This can be changed inside the file if you like.

The database is also modified to make the change permanent within Zotero.

I highly recommend backing up your files and database before trying this, and remember to change the database = and path = fields in the file.

Currently I have each file copied instead of moved to make sure that the nothing gets lost, but that function can be changed by changing :
os.system("copy..." to os.system("move..."

let me know if you need any further help.

link: http://www.box.net/shared/ot1jp9obk6

Done____
Change file name on computer
Change path in zotero database
Change attachment name in zotero as well.
Better commenting
  • PS.

    I have only tested this on Windows with FF3, however I do not believe the SQLite databases are different between operating systems
  • Nice. Would be cool if zotero would save to a standardized filename itself instead of having to do something like this yourself.
  • wouterstomp,
    Agreed, it would be great if Z integrated the ability to extract bibliographic metadata from PDFs and rename the PDF file (but presently it does not). I believe Quosa (commercial software) does this. And I guess Z v1.5 will attempt to extract metadata and create a citation (but will not rename the PDF (is this correct ?).
  • Please please please. I would love this. Right now I'm contemplating switching to Mac just because of Papers. I would prefer to stay with Windows, though, and this is one of the features that Papers has that Zotero doesn't. I want to be able to access my papers *outside* of Zotero as well, for linking into notetaking apps, sending files to other researchers with well-formed informative file names, etc. This is one of the key missing features. I would also like to make "download this PDF, rename it how I say and put it where I say, then link it to the current item" be a smoother fewer-clicks operation.

    Right now I find the paper, use the browser to save the PDF so I can rename it and put it where I want, then create a Zotero item for the page, then link the PDF to the Zotero item. This is very clunky.
  • Try the script, I am using it on 1.0.7, so I don't know if it will still work with 1.5.

    I could also try to post the code on the forum, but it probably won't work as python requires tab consistency.
  • hi,
    I am curently using a perl scribt which renames the most recent pdf in a certain location (in my case the "downloads" folder) according to information about the most recent article added to Zotero ([lastname]_[year]_[title], lastname is lastname et al if there are multiple authors and title is up to 50 characters long) and moves this renamed file to a certain location (my literatur folder). The scribt does not link the file to the Zotero database. I have to do this manually. So I add an article to Zotero, download the pdf to the download folder, press the icon to start the perl scribt and then manually link the pdf-file to the Zotero item.

    I have to problems with this: a) the scribt does not work for 1.5 which I am using since last week, b) it would be much better if the scribt also automatically links the pdf-file to the Zotero item. This would greatly enhance the workflow.

    Would it be possible to do this after changing some stuff in your scribt?
  • A second question:
    Some years ago I started to not put all my pdfs in one folder but in subfolders named "A-B-C", "D-E-F" etc. I figured that this decision was very dull so I would like to copy all these pdfs to one folder not using the subfolder system. The problem is that all these pdfs are linked to Zotero. Since there are several hundred if not about 1000 pdfs, I not very much in favor of doing this manually.
    In addition, I will change to Mac in the not so far future which also requires to change the base directory of all the linked pdfs.
    Is there a way to do this automatically with your scribt?

    Thanks!!
  • Worked Great! Thanks! Let us know when the script will replace the old pdf - and rename it in zotero!

    Fabulous.
  • edited October 14, 2008
    @ jodler
    -If you copy your base directory and database over to your mac, you should maintain the connecitons.
    -For your rename in mass requirement, I know we can find the name and rename it in zotero while preserving the links, actually, this gives me an idea to rename all files, take them out of their individual directories and create an entirely new file system like:
    "attachments\Journal Name\File Name.pdf".
    Tell me if you would like that.
    I know the perl script you are talking about, and actually made this python script because of it, however I wanted to access and change the DB instead of making and deleting entries.

    @ kati42
    Have you tried the script, it should do exactly as you want right now.

    Additionally, has anyone had any problems with this and 1.5? I still haven't moved over to that version, and I am not sure its necessary at this point.
  • Thanks for the reply.

    My mac transfer problem is related to the linked attachments, since all of them will be in a different location. Accordingly, a rename mass utility would (probably) solve the problem too.
    I personally would be more interested in putting all the files in one directory (they are currently in different folders) so that I can jump to the papers of certain author just by pressing the first letter of his/her name.

    Even though I have not tried it, I would guess that the script is not working with 1.5 because the database structure is different.
  • Could you please specify how to use your renaming script, please? Should it be inserted into ZOTERO´s folder?
    Thank you ver much
  • Doesn't seem to work on Sync Preview; works wonders on 1.0.9, though. I would like to second (third? fourth?) the requests to have more intelligent PDF naming/organization in Zotero.

    Lanius: Simply edit the paths to zotero in the script (using any text editor) and run it from any directory (you must have python of some kind installed; any unix OS, including Mac OS, should already have it.) Something like: python /path/to/script.py in the terminal.
  • Hey Scio,

    It would be great if this could work in sync preview - although I've no idea how much work it would take. My data is now all in a sync preview database (which by the way, works great), so cannot be updated the normal way.

    I assume if the local info is changed and then a sync is run, that all will work ok... and sync with other computers will work..but I don't know.

    Fraid my programming is limited to MATLAB, so bit out of my depth with sql etc.
  • neuro,

    Now that I took a look at the database, it doesn't seem to be a big issue to make the change to 1.5

    I don't know with sync though.

    What I have done to stay off the sync protocol is put my entire zotero folder on Dropbox, which can then sync the database and all attachments simultaneously on all my boxes anytime one of them changes, you just need to make sure and use zotero only on one machine at a time, and close Firefox when you move to another machine so that the database is closed and update properly, otherwise there is a chance that your update might never get implemented.
  • As for running python, I am going to try py2exe and see if it works so that people will not need to install python to run the script.
  • Hi Scio,

    thanks for a this really great script. I've been using it for months now and it really helped me alot. Unfortunately I had to upgrade to Zotero 1.5b2 now for several other reasons, which now made this script aborting with some errors (sqlite3.OperationalError: database is locked). So, if there's any workaround or update for this script - I am so looking forward to it.

    But hey, thanks alot again for this great script!
  • Hi everyone,

    I am new to Zotero and excited about all of the features and the community. Unfortunately I am not a programmer, but am interested in using some of the features that you all have created. I am nervous, however, about trying to implement them because I don't entirely know what I am doing. Any help you could offer on how to use this script specifically would be great, do I have to download python?

    Thanks!
    -Nicole
  • ---
    wouterstomp,
    Agreed, it would be great if Z integrated the ability to extract bibliographic metadata from PDFs and rename the PDF file (but presently it does not). I believe Quosa (commercial software) does this. And I guess Z v1.5 will attempt to extract metadata and create a citation (but will not rename the PDF (is this correct ?).
    ---

    Just an FYI for those of you interested in what is available with Quosa, I checked into it using the trial software. The positives were that it ran mass searches for citation information when I imported my existing PDF files (was able to identify 1/2 of my collection) and also automatically located PDF's/full-text articles for all of the references that I imported. These were run on my entire citation and PDF collections, rather than one at a time. The drawbacks were that (1) if I wanted to keep using it, I would have to pay money, (2) it only renames the files with article info within Quosa itself, the actual PDF's are assigned names that only make sense to Quosa, (3) It only utilizes Pubmed for locating information about your PDF library even though it will retrieve information to acquire a PDF document or reference using many more sites and (4) data went missing in the transition back to Endnote, (e.g. years), including that PDF files are not transported but instead links are included to their current location. Also, these citations were unreadable by Zotero, even after being read into Endnote first. Tricky stuff, this reference software business...
  • I have started to get back into this script. I am analyzing the sqlite DB right now and will see if the upgrade is doable
  • Wow! That is so great to hear! I already really missed the tool, since I start using the new beta.
  • Does anyone know how this project has been coming along? Or are there other ways to do the same thing? I'm aware of both the native and non-native ways of renaming files to match parent data, but I'd really, really like a way of doing this with ALL of my files at once. I gather that this tool once made this possible.
  • cantabrian: You can rename multiple files at once using the built-in method—just select more than one item before right-clicking. You can search for attachments with a saved search and use Select All to select all search results.

    This is a new feature, so, to be safe, make sure you have a backup of your Zotero data directory first before renaming lots of files.
  • As it turns out, I tried doing this already, but I can't seem to get the right-click contextual menu to give me the option of renaming the files. Am I doing something wrong? My saved search includes all with "attachments is pdfs," I press cmd + A (which highlights all of them), but right clicking does not bring up the rename option. Strange. Is this perhaps because I'm trying to rename a thousand files at once?

    Is it dumb, by the way, to try this on so many files right now? Perhaps better to wait until the tool's been around for longer?
  • @ cantabrian

    When creating a Saved Search based on "Attachment File Type is PDF", Zotero includes entries whose attachments are links to PDFs (e.g. added via "Attachments --> Add --> Save Link to Current Page" when a PDF is open in your browser). As these are links, not locally stored PDFs, the "Rename File..." option does not appear.

    If you manually deselect such attachments (after highlighting all attachments using cmd + A or Ctrl + A in your Saved Search folder), the option "Rename Files from Parent Metadata" will appear when right clicking on an item in the remaining selection.
  • I can't download the python code from http://www.box.net/shared/ot1jp9obk6, could anyone be kind enough to send me a copy to email: linwen2009@gmail.com, thanks a lot!
Sign In or Register to comment.