Batch rename Word (.doc) files based on first line of text

I have recently recovered a large amount of "lost" data from a drive, but was unable to recover the files with their proper names. (The recovery software just named them 0000A0A0.DOC, 0000A0A1.DOC, 0000A0A3.DOC...)
There are over a thousand documents, so I would like to rename the file with text extracted from the document itself. I was thinking, from the first line of text. This would making sorting much easier.
Does anyone know if this is possible with a batch file or something?
icsbudapestAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Joanne M. OrzechManager, Document Services CenterCommented:
Well here's one from one of our MVPS
http://gregmaxey.mvps.org/Batch_Rename_Files.htm

Also....you'd have to modify this one as well
http://support.microsoft.com/kb/139724
0
Shift-3Commented:
Paste the script below into a text file with a .vbs extension.  Customize the value of the strFolder variable with the folder containing the documents.  Customize the value of the intChars variable with the number of characters to use from the first line.  Running the script will rename each .doc file in the folder.


'Adapted from http://www.microsoft.com/technet/scriptcenter/resources/qanda/apr06/hey0404.mspx
 
strFolder = "c:\files"
intChars = 20
arrRemove = Array("\", "/", ":", "*", "?", Chr(34), "<", ">", "|")
 
On Error Resume Next
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strFolder)
 
Set objWord = CreateObject("Word.Application")
 
For Each strFile in objFolder.Files
    arrNames = Split(strFile.Name, ".")
    strExt = arrNames(UBound(arrNames))
    If LCase(strExt) = "doc" Then
        Set objDoc = objWord.Documents.Open(strFile.Path)
        Set objRange = objDoc.Range(0,intChars)
        strRange = objRange.Text
        
        For Each strChar in arrRemove
            strRange = Replace(strRange, strChar, "")
        Next
        
        strNewName = strFolder & "\" & strRange & "." & strExt
 
        objDoc.Close
        Wscript.Sleep 3000
        objFSO.MoveFile strFile.Path, strNewName
    End If
Next
 
objWord.Quit

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
icsbudapestAuthor Commented:
The script seemed to work well. Thank you. Just what I needed. (It may take all day to run it, but will be a time saver in the long run.)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.