How do I delete macro(s) from several hundred .odt documents (some are converted .doc documents)?

LO ver 4.1.5.3
Writer
English
Win7

If you are a fan of python, then the following script will rename your files to oldname-new.ods and strip Basic directory from the file, which gets rid of the scripts. It will however not check if you actually do use the scripts, so you better have a backup of the original files until you are sure all the files work correctly. To run it type to command line C:\Python2.7\python.exe filename.py *.ods when in correct directory. Also you would have to install python :slight_smile:

#!/usr/bin/python

import glob, os, sys, zipfile

for pattern in sys.argv[1:]:
    for filepath in glob.glob(pattern):
        dirname, basename = os.path.split(filepath)
        root, ext = os.path.splitext(basename)
        newname = '%s-new%s' % (root, ext)
        outpath = os.path.join(dirname, newname)
        zin = zipfile.ZipFile (filepath, 'r')
        zout = zipfile.ZipFile (outpath, 'w')
        for item in zin.infolist():
            if item.filename == 'mimetype':
                zout.writestr(item, zin.read(item.filename))
        for item in zin.infolist():
            if item.filename != 'mimetype' and item.filename[:6] != 'Basic/':
                zout.writestr(item, zin.read(item.filename))
        zout.close()
        zin.close()

Credits for being helpful to http://stackoverflow.com/questions/4957212/how-does-open-office-compress-its-files and http://stackoverflow.com/questions/513788/delete-file-from-zipfile-with-the-zipfile-module

Oh, and if using *.ods should create a too long command line, then put it inside quotes, “*.ods”, then glob will take care of it.