View Full Version : Rename recovered files
rachanta
11-19-2017, 05:50 AM
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.
rachanta
11-19-2017, 10:32 AM
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.
macropod
11-19-2017, 01:41 PM
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.
macropod
11-19-2017, 09:46 PM
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.
rachanta
11-19-2017, 11:30 PM
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 .
macropod
11-20-2017, 12:33 AM
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.
rachanta
11-20-2017, 02:47 AM
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.
macropod
11-20-2017, 03:08 AM
That's not a problem with the code but with your system permissions. The code can't do anything about that.
gmaxey
11-20-2017, 07:21 AM
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/installing_employing_macros.html
macropod
11-20-2017, 12:52 PM
rachanta: You asked for help with essentially the same problem in two different threads, which I've now merged.
One thread per topic, please.
rachanta
11-23-2017, 11:46 PM
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.
macropod
11-24-2017, 04:32 PM
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.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.