1

I have a hard drive containing files with names that have been formatted by the "File History" feature of windows. A typical file name looks like this:

Randomfile - blah (2015_05_29 14_56_40 UTC).docx

or

1415374402647_res_original (2015_05_31 15_33_12 UTC).jpg

What I need to do, is remove the date/time stamp that is present at the end of each file. There are too many files to do it manually and that's why I wish to use powershell and regex to do this for me. It also needs to be recursive so it will search sub folders too.

My OS is Win7 Ultimate.

1
  • You could certainly do that in PowerShell, but I think it would be easier to use a renaming tool. There are many of them out there. I like AdvancedRenamer.
    – dangph
    Commented Dec 14, 2015 at 6:42

1 Answer 1

0

Well if all you want to do is delete everything in the last set of brackets (I'm assuming all dates are in brackets):

Get-ChildItem -Recurse | Rename-Item -NewName {
    $file = $_.FullName.Substring(0, $_.FullName.LastIndexOf("(")).Trim()
    $file + $_.FullName.Substring($_.FullName.IndexOf(")") + 1)
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .