Last active
November 9, 2023 14:34
-
-
Save ZiTAL/c9b07ca67ead13b36769d348b9086ce4 to your computer and use it in GitHub Desktop.
python: change modification date to folders/files from lower to higher date alphabetically
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
#!/usr/bin/python3 | |
# -*- coding: utf-8 -*- | |
# usage: python3 fmod.py "/home/zital/Music" | |
import os, sys, datetime | |
def getResources(path): | |
resources = [] | |
for root, dirs, files in os.walk(path): | |
resources.extend( | |
[os.path.join(root, dir) for dir in dirs] | |
+ | |
[os.path.join(root, file) for file in files] | |
) | |
resources.sort() | |
return resources | |
date_str = "1980-01-01 00:00:00" | |
date_start = datetime.datetime.strptime(date_str, "%Y-%m-%d %H:%M:%S").timestamp() | |
date_diff = 86400 | |
try: | |
#path = "/path/to/your/folder" | |
path = sys.argv[1] | |
except: | |
print("Required: Folder path as argument.") | |
sys.exit(1) | |
if(os.path.isdir(path) == False): | |
print("Error: Folder doesn't exists.") | |
sys.exit(1) | |
resources = getResources(path) | |
for resource in resources: | |
os.utime(resource, (date_start, date_start)) | |
date_start = date_start + date_diff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment