Consulting

Results 1 to 12 of 12

Thread: Rename recovered files

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Rename recovered files

    Hi, I recently ended up accidentally formatting all my disks including backups. I engaged a specialist and retrieved most of the data.

    I now have many thousands of powerpoint, excel and word files named like Found_297934336_13592064.

    I need some help with code to rename my powerpoint files with the presentation Title and similarly with my docx and xlsx files.

    I am a complete newbee in Visual Studio though I have done development in Linux environments using C or Python. Your code is right now my only hope and I am going crazy trying to run it in Visual Studio. I realised that I had not chosen the version with Visual Basic. I am now downloading hopefully the right version and will try again. Is there a simpler way than download 3.54 GB of Visual Studio Express. With my current download speed, it might take for ever.

    Meanwhile, to be sure, I would like to know what development environment, plugins or any other prerequisites are required for running your code. Thanks in advance. I am stuck and badly need help.
    Last edited by macropod; 11-19-2017 at 09:33 PM. Reason: Split from http://www.vbaexpress.com/forum/showthread.php?59002-Renaming-ppt-file-name-with-Slide-1-tittle-name

  2. #2
    I need to rename thousands of doc and docx files using the Title field or first text if the file. I tried running your code as console app but end with a number of error debug messages and a system error:...console app1.exe is missing please build the project and retry....Please tell step by step what exactly I should do to rename as mentioned above. Sorry I am total vb noob.

  3. #3
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    I don't know what your answer to Paul's question will be, but to employ the macro discussed here with Word, see:
    http://gregmaxey.com/word_tip_pages/...ng_macros.html
    Greg

    Visit my website: http://gregmaxey.com

  4. #4
    Thanks Greg. I realise I actually did not setup the macro properly. In the mean time I came across a VB script for word files that I could rename a few of my files with. With that and finding duplicate files with a utility I completed the job with all my *.doc files. I still have many thousands if docx, ppt, pptx files to deal with. I'll use your guide to setup your macros and try. Thanks for helping out.

  5. #5
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    So why don't you just reload your files from your backups? Seems a whole lot simpler to me. At most you'd then only have the latest files to fix.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  6. #6
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Quote Originally Posted by rachanta View Post
    I recently ended up accidentally formatting all my disks including backups.
    How is it even possible to accidentally format all disks including backups???

    With decent recovery software, even the original filenames can usually be recovered.

    As it is, filenames like Found_297934336_13592064 are pretty meaningless; there is no way of telling what kind of file they are (e.g. exe, dll, bin, txt, doc, docx, docm, dot, dotx, dotm, xls, xlsx, xlsm, ppt, pptx, pptm, psdt, ost, etc., etc.). Before you can do anything meaningful, you'll need some software to analyse each and every file to determine its type and apply the appropriate file extension. Only then might you be able to use Excel, PowerPoint, Word, etc. to do the kind of renaming you're after. Or you could try using recovery software better suited to the task.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  7. #7
    How I got the point is long story...while making a new triple boot win, Mac, Ubuntu computer.
    I repartitioned both the HD as well as external HD and then copied new folders from a server onto the newly formatted exfat data drives.
    The disk recovery expert could not find the FAT / File structure because of the overwriting. What I have is a dump with random alphanumeric names, but with file extensions.

    I have folders of doc, docx, ppt, pptx files with extensions...so there is hope. There are thousands of files, some duplicates as well . Naming manually is an onerous task. I need help in automatically finding titles of ppt files, or initial strings of doc files and renaming files as per those strings .

  8. #8
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    For Word documents, you might use something like the following Word macro:
    Sub RenameDocuments()
        Application.ScreenUpdating = False
        Dim strFolder As String, strFile As String
        Dim strDocNm As String, strNewNm As String
        Dim strNames As String, wdDoc As Document, i As Long
        Const StrNoChr As String = """“”*.,/\:?|" & vbTab
        strDocNm = ActiveDocument.FullName: strNames = ","
        strFolder = GetFolder
        If strFolder = "" Then Exit Sub
        strFile = Dir(strFolder & "\*.doc", vbNormal)
        While strFile <> ""
            If strFolder & "\" & strFile <> strDocNm Then
                Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
                With wdDoc
                    For i = 1 To .Paragraphs.Count
                        With .Paragraphs(i).Range
                            If Len(Trim(.Text)) > 1 Then
                                strNewNm = Trim(Split(.Sentences.First, vbCr)(0))
                                Exit For
                            End If
                        End With
                    Next
                    For i = 1 To Len(StrNoChr)
                        strNewNm = Replace(strNewNm, Mid(StrNoChr, i, 1), "_")
                    Next
                    If InStr(strNames, "," & strNewNm & ",") > 0 Then
                        strNewNm = strNewNm & " (" & Split(strNames, "," & strNewNm)(UBound(Split(strNames, "," & strNewNm))) + 1 & ")"
                    End If
                    strNames = strNames & strNewNm & ","
                    strNewNm = strNewNm & "." & Split(.Name, ".")(1)
                    .Close SaveChanges:=False
                End With
                Name strFolder & "\" & strDocNm As strFolder & "\" & strNewNm
            End If
            strFile = Dir()
        Wend
        Set wdDoc = Nothing
        Application.ScreenUpdating = True
    End Sub
     
    Function GetFolder() As String
        Dim oFolder As Object
        GetFolder = ""
        Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
        If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
        Set oFolder = Nothing
    End Function
    You could use something similar for PowerPoint, looping through slides and shapes till you find one with text content. You could also use something similar with Excel by looking for the first cell that doesn't have a formula.

    Now that I've given you the code for Word, you should study other threads on this board for hints on how to adapt it to work with PowerPoint and Excel.
    Last edited by macropod; 11-24-2017 at 04:30 PM.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  9. #9
    Tried the code. It errors out saying "You don't have permissions...".

    I am still seeing if I made a mistake somewhere. Thanks a lot for helping out.

  10. #10
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    That's not a problem with the code but with your system permissions. The code can't do anything about that.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  11. #11
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    rachanta: You asked for help with essentially the same problem in two different threads, which I've now merged.

    One thread per topic, please.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  12. #12
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Note: I've revised the code to make it more efficient. Whereas the original code would re-save the recovered file with a new name, resulting in your system having both versions, the revised code simply renames the recovered file.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •