Skip to content

Instantly share code, notes, and snippets.

@srustagi
Last active November 27, 2022 20:30
Show Gist options
  • Save srustagi/791f7631e3cfbc2581b9415f2ba39da2 to your computer and use it in GitHub Desktop.
Save srustagi/791f7631e3cfbc2581b9415f2ba39da2 to your computer and use it in GitHub Desktop.
Remove UTC timestamp from Windows File History Backup for all files in folder recursively, skip over duplicates.
import re
from os.path import join
from os import walk, rename
FOLDER_PATH = join('PATH_TO', 'DIR_NAME')
for path, subdirs, files in walk(FOLDER_PATH):
for i, name in enumerate(files):
fixed = re.sub(r' \(.+\)', '', name)
print('{} / {}'.format(i + 1, len(files)))
try:
rename(join(path, name), join(path, fixed))
except FileExistsError:
continue
@Erisa
Copy link

Erisa commented Sep 6, 2020

Thank you for this simple but amazing script! Used it to recover files from a File History drive that was erroring through Windows, possibly a corrupted db (Ironic, I know)

One thing I observed was that it skips over files without file extensions. To resolve this I changed the regex line to:

fixed = re.sub(r' \(.+\)', '', name)

Which appeared to work for my files at least, haven't thoroughly tested so results may of course vary!

@srustagi
Copy link
Author

srustagi commented Sep 7, 2020

you're welcome! I had no idea this script would ever be used by anyone but me 😂😂. I'll update the gist, thanks for the fix!

@RegBl
Copy link

RegBl commented Jun 14, 2021

I've been putting off trying to write something like this myself. Then I found this!

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment