Created
June 24, 2024 08:30
-
-
Save simryang/8e31d54c4bd7d3823ab17c7d8e5927bb to your computer and use it in GitHub Desktop.
rename files from timestamp name to formatted name
This file contains 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
from pathlib import Path | |
from os.path import splitext, dirname, rename | |
from os import rename | |
def move_pathlib(src_full: Path): | |
# filename = "/home/pi/1709705942.jpg" | |
newname = datetime.fromtimestamp(int(src_full.stem)).strftime("%Y-%m-%d_%H-%M-%S") | |
npp = Path(pp.parent, newname).with_suffix(pp.suffix) | |
src_full.rename(npp) | |
def move_str(src_full: str): | |
# filename = "/home/pi/1709705942.jpg" | |
parent = dirname(src_full) | |
orgname, ext = splitext(basename(src_full)) | |
newname = datetime.fromtimestamp(int(orgname)).strftime("%Y-%m-%d_%H-%M-%S") | |
rename(src_full, parent + "/" + newname + ext) | |
def move_str2(src_full: str): | |
# filename = "/home/pi/1709705942.jpg" | |
orgname = splitext(basename(src_full))[0] | |
newname = datetime.fromtimestamp(int(orgname)).strftime("%Y-%m-%d_%H-%M-%S") | |
return src_full.replace(orgname, newname) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment