Posted by & filed under Moodle, Programming.

Edit on 8/7/2014

Well, this script is pretty much worthless now. Not sure when it happened, but Moodle now lets you upload the entire Blackboard zip file, images included, and everything gets imported. No more messing around with the res00000 files.

Going to leave the original post though. Might be handy for someone stuck using an older version of Moodle.

Original Post

I’m a big fan of Moodle, but really don’t like the way you have to add questions to banks. There’s just too much on that page.

So I normally build question banks in Examview and then import to Moodle. Only catch is that importing that way doesn’t allow for images.

So what I’ve done is create a simple Python script that takes the exported file and replaces the image links with a data scheme URI. Wasn’t expecting it to work, but it works without a hitch.

The Script

Convert a Blackboard export file (res00000.dat) to include
all images as base 64 encoded data URI schemes instead of
linking to the actual file so that it can be imported into
import re, sys, string

in_file = open('res00000.dat', 'r')

data =

matches = re.findall('<img.*?src="(.*?)".*?>', data);

print 'Found ' + `len(matches)` + ' images'

for match in matches:
    image_file = open('res00000/' + match, 'rb')
    image_base64 ='base64', 'strict').replace('\n', '')

    content_type = 'image/png'
    if match[-4:].lower() == '.jpg':
        content_type = 'image/jpeg'
    elif match[-4:].lower() == '.gif':
        content_type = 'image/gif'
    data = string.replace(data, match, 'data:' + content_type + ';base64,' + image_base64)

out_file = open('converted.dat', 'w')


print "Converted file saved to converted.dat"

Exporting from Examview

Exporting from Examview to Blackboard 6.

Exporting from Examview to Blackboard 6.

To get the file out of Examview you’re going to export the question bank as a Blackboard version 6.

The file that will save is a .zip fie containing a file named res000000.dat, a xml file, and possibly a folder of resources if your bank includes images.

You’ll need to unzip the file from Examview into a folder to work from.

Running the Script

What I normally do is copy the Python file into the same folder you just unzipping into – the one with res00000.dat and then double click.

What the script does is open the res00000.dat file and run a regex match on any HTML <img> tags. It then loads the requested image from the resource directory and base64 encodes it. The encoded data is then put back into the data file in place of the link. And last the file is saved with a new name.

The script tells you how many files it encoded when done.

Once you’re finished you’ll import the converted.dat file that’s created into Moodle using the Blackboard 6 option.


There is no error checking in the script. It just crashes out if there’s a problem. For me that’s not an issue but I may go back and work out a way to have it fail a little more gracefully if there’s an issue.

I’d also like to add the option for command line arguments so you can specify the incoming and outgoing filenames.


I’ve spent the last couple of days setting up a new instance of Moodle for next year, this time with version 2.7, and the question editing screen is much better. Still think ExamView is still going to work better for me when I’ve got a lot of questions to load in, but for a handful adding them directly in Moodle isn’t going to be so bad.

Leave a Reply

Your email address will not be published. Required fields are marked *