Created
March 24, 2020 12:54
-
-
Save mitsuhisaT/995bb0be488008efe5a2f83beea81cc8 to your computer and use it in GitHub Desktop.
rename many directories by Python via Regular expression and Pathlib.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
import os | |
import re | |
from pathlib import Path | |
for dn, dps, fns in os.walk('.'): | |
if re.search(r'\./.+_\d{8}', dn) is not None: | |
# rename to 20200324_test from test_20200324 | |
Path(dn).rename(Path(re.sub(r'(\./)(.+)_(\d{8})', r'\1\3_\2', dn))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment