Skip to content

Instantly share code, notes, and snippets.

View prince-ravi-leow's full-sized avatar

Prince Ravi Leow prince-ravi-leow

View GitHub Profile
@prince-ravi-leow
prince-ravi-leow / overwhy.py
Created March 7, 2024 15:07
Prevent file overwriting with this simple trick (sysadmins hate him!)
def overwhy(dir, basename, ext):
"""
Prevent file overwriting by appending formatted date+timestamp for non-unique filename.
Example:
Following non-unique filename query:
dir: output_dir/, basename: results, ext:txt
Yields:
"output_dir/result_20240307_160534.txt"
"""
import time