-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorganizeByDate.py
More file actions
23 lines (22 loc) · 1.06 KB
/
Copy pathorganizeByDate.py
File metadata and controls
23 lines (22 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import os
from pathlib import Path
import time
def organizeDirectory():
for item in os.scandir():
if item.is_dir():
continue
filePath = Path(item)
fileDateRaw = os.path.getmtime(filePath)
fileDate = time.ctime(fileDateRaw)
year = fileDate[20:24]
month = fileDate[4:7]
day = fileDate[8:10]
directory = year + " " + month + " " + day
directoryPath = Path(directory) # Creates a new pathway in the PC for the file movement
if directoryPath.is_dir() != True: # If the path doesn't have an actual directory
directoryPath.mkdir() # Make a directory (a folder) that has the name of "directory" variable.
filePath.rename(directoryPath.joinpath(filePath)) # Takes the path of item and renames it to: the directory
# concatenated with the the file name.
# Ex. From /etc.jpg -> /newDirectory/etc.jpg
print(directory)
organizeDirectory()