TL;DR: A Python daily folder fairy script is helping me keep production files organized at my new job!
So I started a new job the other daaaaaaaay! I’m two weeks into being a fabricator at a local manufacturing shop and it’s so much fun, but I will need to keep my folders organized to a T! So I decided to write a daily folder fairy to automate some of the work for me!
Part Un: The Context
Alright, let’s break down what I need the script to do.
I’m going to be getting jobs orders from customers everyday: we have a centralized jobs and files management system we all work from, but I plan to have a main JOBS
folder on my own computer created automatically everyday. But that’s not all!
The JOBS
folder will have sub-folders for 3D printers and CNC routers projects, and all of these folders will feature the day’s date as well. Something like JOBS_07142025
, 3DPRINTS_07142025
and CNC_07142025
for example!
From there, I can just drop the work files to the relevant folders and start working on them! And after the day is done, I can hold on to them for a while for traceability. After that they can be deleted, or moved to our evergreen storage on the main jobs management system.
So let’s break down what that means in Python terms! The script will need to:
- Pull the date and time from the system clock using the
datetime
module. - Create unique folders and sub-folders names and paths using the
pathlib
module. - Create the actual folders and sub-folders based on the paths using the
os
module
Part Deux: Implementing Features
I was able to pull the date and time from the system clock using the datetime
module with a tiny script, based on the usual documentation.
import datetime
#See doc at https://docs.python.org/3/library/datetime.html
x = datetime.datetime.now()
print(x.strftime("%m%w%Y"))
With a reliable date and time stamp in tow, it was time to figure out handling paths with pathlib
. Getting more practice with this module was actually part of the motivation for this script! Here’s what I got!
import os
#See doc at https://docs.python.org/3/library/os.html#module-os
from pathlib import Path
#See doc at https://docs.python.org/3/library/pathlib.html
folderParent = "folderName"
folderCNC = "CNC"
folder3DPrints = "3D_Prints"
nestedFolderCNC = Path(f"{folderParent}") / f"{folderCNC}"
nestedFolder3DPrints = Path(f"{folderParent}") / f"{folder3DPrints}"
try:
nestedFolderCNC.mkdir(parents=True, exist_ok=False)
nestedFolder3DPrints.mkdir(parents=True, exist_ok=False)
except FileExistsError as e:
print("The folder already exists")
except PermissionError:
print(f"Permission denied: Unable to create '{folderName}'.")
except Exception as e:
print(f"An error occurred: {e}")
After that, it was time to bring everyone together! I brought everything in a fresh Python file and started reorganizing things around, with help from my notes and diagrams, and Mistral’s Codestral running in a local instance of MSTY. Has anybody else had really bad experiences with the latest, “thinking” versions of Large Language Models? They seem to veer into hallucination country so fast! But keeping Codestral on task on small functions and modules was very easy.
Here’s the final version of our code!
import datetime
#See doc at https://docs.python.org/3/library/datetime.html
from pathlib import Path
#See doc at https://docs.python.org/3/library/pathlib.html
def create_folders(parentFolder, *subFolders):
"""Creating date-stamped folders under a parent folder"""
#Getting the current date and formatting it in MMDDYYYY format
x = datetime.datetime.now()
todaysDate = x.strftime("%m%w%Y")
print(f"Today's date is {todaysDate}. Let's create the folders you need!")
#Creating paths for the parent folder
parentFolderPath = f"{parentFolder}_{todaysDate}"
#Tuple for storing the subfolder paths
subFoldersPaths = []
# Creating paths for the subfolders
for subFolder in subFolders:
subFolderPath = (f"{subFolder}_{todaysDate}") #Formatting the subfolder path by combining subfolder and date with an f-string
completePath = Path(parentFolderPath) / subFolderPath
subFoldersPaths.append(completePath)
try:
completePath.mkdir(parents=True, exist_ok=True)
except OSError as e:
print(f"Something didn't work out - {e}")
return(subFoldersPaths)
dailyFolders = create_folders("JOBS", "CNC", "3DPrints") #Calling the folders creation function with our subfolders as parameters
print(dailyFolders) #Printing out the results
Codestral actually suggested using OSError rather than three different types of errors, which I thought was pretty smart. My refactoring and variable names are a little funky but it should do the job! I will start using this script on my work computer after some extra testing, and have Windows run it automatically once daily on startup.
And that’s it for my Daily Folder Fairy! From concept to finished script, it took me a morning’s worth of work. You can grab the finished script and each intermediary step on Github. Use it in good health!
If you want to read more about my experiments with Large Language Models and programming, check my write-ups on the 8-Bit To Do App and the Multiverse Travel Immersive Experience!