0

I have a windows file system where a hiccup in our backup software renamed hundreds of files.

The change looks like this:
"ABC.PDF" -> "ABC.PDF.BAK"

This happened to some, but not all files in a directory.

I would like to rename such files to their old name, but the script should output or ignore cases where this is not possible, because a "ABC.PDF" already exists.

I am not familiar at all with batch scripts, but powershell is available too.

Hennes
  • 65,804
  • 7
  • 115
  • 169

1 Answers1

1

You can do something like this in powershell:

$files = dir *.BAK
foreach($file in $files) {
    Rename-Item $file $file.BaseName -ErrorAction Ignore
}

There will only be an error if those files no longer exist, or if you are trying to overwrite a file.

If you want to see what it will do first, add the -WhatIf flag.

soandos
  • 24,600
  • 29
  • 105
  • 136