Last active
December 11, 2016 18:34
-
-
Save matolg/99fba4eaa0e6263dd54df3934ce84096 to your computer and use it in GitHub Desktop.
Rename all files in directory with modification date
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 os import listdir, rename | |
from os.path import isfile, join, getmtime, splitext | |
from time import gmtime, strftime | |
pathToFiles = "E:/test" | |
nameFormat = "%d%m%Y_%H%M%S" | |
files = [f for f in listdir(pathToFiles) if isfile(join(pathToFiles, f))] | |
for f in files: | |
originFullPath = join(pathToFiles, f) | |
originFileName, fileExtension = splitext(f) | |
createdTime = getmtime(originFullPath) | |
newFileName = strftime(nameFormat, gmtime(createdTime)) + fileExtension | |
newFullPath = join(pathToFiles, newFileName) | |
rename(originFullPath, newFullPath) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment