Last active
July 7, 2016 09:30
-
-
Save enghqii/006713d108ebae5af319 to your computer and use it in GitHub Desktop.
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
import os | |
import time | |
import datetime | |
currentPath = os.path.dirname(os.path.abspath(__file__)) | |
filenames = os.listdir(currentPath) | |
for filename in filenames: | |
# full file path of files in current directory | |
fullFilePath = os.path.join(currentPath, filename) | |
# for files | |
if os.path.isfile(fullFilePath): | |
# not for me | |
if fullFilePath == os.path.abspath(__file__): | |
continue | |
try: | |
fileCTime = os.path.getctime(fullFilePath) | |
cdatetime = datetime.datetime.fromtimestamp(fileCTime) | |
#print("src : " + fullFilePath) | |
destPath = os.path.join( | |
currentPath, | |
str(cdatetime.year), | |
str(cdatetime.month) | |
) | |
#print("dest : %s" % (destPath)) | |
if not os.path.exists(destPath): | |
os.makedirs(destPath) | |
os.rename(fullFilePath, os.path.join(destPath, filename)) | |
except FileExistsError as exception: | |
print("FileExistsError occured : " + filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment