0

Something went wrong with backup and recovery when I was resetting my laptop. Now I am left with all my files looking like this:File names after error in backup

I tried to re-add the drive as a recovery option through windows recovery (hoping that if I was able to do the recovery, the software would automatically bring all these files back onto my laptop without the backup date information), but the windows recovery tool refused to recognize the FileHistory that had been saved onto this drive.

Now I am looking to just cut-paste (move) these files onto the laptop and am looking for a way to remove that backup date information.

I have already done so manually for a few files before realizing there must be a way to automate this tedious task.

Is there a way to rename all these files in a way so that the backup date information is removed without having to download any external software?

I read through How can I mass rename files? but am still unsure of what to do.

Preferences:

  • Rename happens while the entire folders are moved from external drive to the laptop
  • Not have any changes made to file details such as "Date Modified"

EDIT:

Example: The backed-up file is at the following location on my external drive:
D:\FileHistory\myuser\LAPTOP-78RBSL7E\Data\C\Users\myuser\Desktop\Education\High School\G12\Politics

It should copy to this location on my laptop:
C:\Users\myuser\Desktop\Education\High School\G12\Politics

The filename should go from Culminating Essay (2021_05_02 18_14_18 UTC) to Culminating Essay

This name change should also apply to zip files

AR.C
  • 47

2 Answers2

2

You can create a batch file to accomplish the task. You copy the code below to notepad and save it with the name that you want but with a *.bat extension.

Change the this part according to your needs and click the batch file set Source= set Destiny=

@echo off
:: here you infrorm the script where the source and destiny are:
set Source=D:\FileHistory\myuser\LAPTOP-78RBSL7E\Data\C\Users\myuser\Desktop\Education\High School\G12\Politics
set Destiny=C:\Users\myuser\Desktop\Education\High School\G12\Politics

:: This gets the full path of the source: for /f "delims=" %%a in ("%Source%") do set Source=%%~dpnxa :: This creates the destiny in case it doesn't exist already: IF not exist "%Destiny%" md "%Destiny%"

:: This sends the full path of each source file to the rename funcion For /f "Delims=" %%a in ('dir /b /s /a-d "%Source%*"') do call :Rename "%%~a"

exit

:: Here the renaming is done: :Rename set "PartName=%~1" call set "PartName=%%PartName:%Source%=%%" for /f "tokens=1,3 delims=()" %%a in ("%PartName%") do set "PartName=%%~a" if "%PartName:~-1%"==" " set "PartName=%PartName:~0,-1%" IF /i not exist "%Destiny%%PartName%%~x1" echo F |xcopy /q /k "%~1" "%Destiny%%PartName%%~x1" goto :EOF

enter image description here

1

Not the most efficient PowerShell code, but the most straight-forward off the top of my head.

$BackupFileRoot = 'D:\FileHistory\myuser\LAPTOP-78RBSL7E\Data\C\Users\myuser'
$RestoreToRoot  = 'C:\Users\myuser'

Recreate Directory Structure

(Get-ChildItem $BackupFileRoot -Directory -Recurse).FullName | ForEach{ $RestorePath = $_.Replace( $BackupFileRoot , $RestoreToRoot ) If ( !( Test-Path $RestorePath ) ) { md $RestorePath -Force | out-null } }

Restore Files

$RegExFind = ' ([\w ]+UTC)' Get-ChildItem $BackupFileRoot -File -Recurse -Force | ForEach{ $RestorePath = $.FullName.Replace( $BackupFileRoot , $RestoreToRoot ) -replace ( $RegExFind , '' ) If ( !( Test-Path -LiteralPath $RestorePath ) ) { Copy-Item -LiteralPath $.FullName $RestorePath } }

AR.C
  • 47
Keith Miller
  • 10,694
  • 1
  • 20
  • 35