Reverse detail from Kakelbont MS 1, a fifteenth-century French Psalter. This image is in the public domain. Daniel Paul O'Donnell

Forward to Navigation

Bulk converting and moving docx files to pdf

Posted: Dec 19, 2020 15:12;
Last Modified: Dec 19, 2020 15:12
Keywords:

---

The issue I had was a set of student assignments downloaded from Moodle. Most were in Word format (.docx), but to grade them quickly I wanted them in pdf.

The Moodle download was a zip file that expanded to a series of directories of the format “studentName/randomwassignmenttitle.docx.” So I also wanted to collect all the files one directory higher up BUT add the student names to the files.

So to put in steps:

  1. I wanted to convert all .docx files to .pdf
  2. I wanted to rename all PDF files in individual directors from $DIR/*.pdf to $DIR/$DIR*.pdf
  3. I wanted to move all pdf files up one directory.

In the end I did it quickly using two scripts:

  1. to convert everything to PDF: find . -name "*.docx" -print0 | xargs -0 unoconv -f pdf *.docx (modified from here)
  2. to add the directory name to the file name and then move it up one: find "$PWD" -type f -name "*.pdf" -exec bash -c ' DIR=$( dirname "{}" ); mv "{}" ../"${DIR##*/}".pdf ' \; (modified from here)

I’m sure I could combine them into a single and more elegant script, but this worked for now.

----  

Comment

:
:

:

Textile help

Back to content

Search my site

Sections

Current teaching

Recent changes to this site

Tags

anglo-saxon studies, caedmon, citation practice, composition, computers, digital humanities, digital pedagogy, grammar, history, moodle, old english, pedagogy, research, students, study tips, teaching, tips, tutorials, unessay, universities

See all...

Follow me on Twitter