View Single Post
Old 05-25-2015, 04:53 AM   #9
Westlyn
Enthusiast
Westlyn began at the beginning.
 
Posts: 33
Karma: 14
Join Date: Jul 2010
Device: Windows Mobile and Android
Quote:
Originally Posted by rebl View Post
I was wondering what tool / utility you have used to "scan .doc files, identify the rtfs and rename the file with the correct rtf extension" - could you please let me (us) know? I couldn't find it using google.
Thank you.
Well sorry to say I wrote myself a word macro so there is no standalone tool I'm afraid.
Code:
Function IsRTF(RTFFile) As Boolean
Dim firstchars As String
firstchars = "aaaa"
Open RTFFile For Binary As #1
firstchars = Input(5, #1)
'Debug.Print firstchars
Close #1
If firstchars = "{\rtf" Then
    IsRTF = True
Else
    IsRTF = False
End If
End Function
and a macro to scan through folders and subfolders from a starting point.

Code:
Sub ConvertDocsToRTF()
Dim fnam As Object, fso As FileSystemObject, ext As String, fld As Object
'browse for folder
Set fso = New FileSystemObject
If Flder = "" Then
startfolder = InputBox("Enter start Folder", "Starting Folder")
End If
Debug.Print "Processing "; startfolder
If fso.FolderExists(startfolder) Then
' process folder contents
For Each fnam In fso.GetFolder(startfolder).Files
    DoEvents
    ext = fso.GetExtensionName(fnam)
    Debug.Print ext; " :>"; fnam
    If IsRTF(fnam) Then
        ' check file extension and rename to .rtf if required
        If LCase(ext) <> "rtf" Then 'file extension is wrong
            'rename file to .rtf extension
            newname = Left(fnam, Len(fnam) - Len(ext)) + "rtf"
            If fso.FileExists(newname) = False Then
                'do the rename
                Debug.Print "Renaming:"
                Debug.Print fnam
                Debug.Print newname
                fso.MoveFile fnam, newname
            DoEvents
            End If
        End If
    End If
Next
' recurse sub folders
For Each fld In fso.GetFolder(startfolder).SubFolders
    Call ConvertDocsToRTF(fld.Name)
Next
MsgBox "Finished", vbOKOnly
End If

End Sub
Please forgive the crudeness of the code but I no longer program for a living and it was only for a one off requirement.

Hope this helps.
Westlyn is offline   Reply With Quote