Long story short I recovered alot of data deleted from a friends hard drive. I can organise MP3 and JPEGs no problem but I cant find a program that will use the Meta data of a DOCX file to rename name. I just want to use Document Title as filename.

Anyone know a program that can do this?


  • I found this perl script which I could maybe modify but this is my last option. Surely someone has wrote a program to do this? Perl Script – amof Jan 30 '13 at 1:06

A docx is actually a zip with a bunch of stuff in XML inside. The title is dc:title inside docProps/core.xml.

EDIT: Wrote a quick python script to do it.

#!/usr/bin/env python

from sys import argv
from zipfile import ZipFile
from xml.etree import ElementTree
from os import rename

for arg in argv[1:]:
    data = ZipFile(arg, 'r')
    props = data.read('docProps/core.xml')
    tree = ElementTree.fromstring(props)
    element = tree.find('{http://purl.org/dc/elements/1.1/}title')
    title = element.text
    if title is None:
        print(arg + ' has no title :(')
        rename(arg, title + '.docx')

It'll process anything given to it as command line arguments. If a file doesn't have a title, it'll tell you and skip it; other than that, no error handling. Everything it uses should be in the standard library.

  • Helpful, possibly, but this doesn't answer the question. – Marcus Chan Jan 30 '13 at 3:44
  • Added some code. – qmega Jan 30 '13 at 4:13

The following Windows script demonstrates how to get the document Title. You'll want to create a file that ends with ".wsf" and paste this into it. Obvoiusly, you'll iterate over your files and rename them as you go. That's the easy part. This is the "hard" part and shown only how to get the Title.

I have CScript set as my default script engine. If you don't, you can run your script from the command line by:

CScript yourScriptName.wsf

You can make CScript the default engine by:

CScript //H:CScript

Once you've done that, your script will run merely by typing its name:


You'll need DSOFile from Microsoft.


<job id="MyJob">

<?job error="true" debug="false" ?>

<script language="VBScript">

Option Explicit

'   Start of main program

Dim filename
Dim title

filename = "testfile.doc"
title = getTitle( filename )

WScript.Stdout.WriteLine title

' Needs DSOFile from http://www.microsoft.com/en-us/download/details.aspx?id=8422
Function getTitle( filename )
   Dim objFile
   Set objFile = CreateObject("DSOFile.OleDocumentProperties")

   objFile.Open( filename )

   getTitle = TrimEx(objFile.SummaryProperties.Title)
End Function

Function TrimEx(str)
   Dim retval

   Dim re
   Set re = New RegExp
   re.Pattern = "^\s*"
   re.Multiline = False
   retval = re.Replace(str, "")

   re.Pattern = "\s*$"
   TrimEx = re.Replace(retval, "")
End Function



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.