Exporting files from Lifecraft and importing to DayOne…

Converting 1700+ RTF files from my old Lifecraft program to plain text so it can be imported into the Day One app sounds simple—until you hit a datestamp snag. My files were named with dates like 5-16-17.rtf, and I needed those dates inside the TXT files as May 16, 2017. What started as a straightforward script turned into a debugging odyssey, but with some Python tweaks and Terminal commands (plus a nudge from my AI buddy, Grok), I got it sorted. Here’s the tale—and how you can do it too.

The Goal: From RTF (Lifecraft) to TXT (DayOne) with Style

I had 1700+ RTF files in /Users/daviddaniels/RTF_Files, each named with a date (e.g., 5-16-17.rtf for May 16, 2017). I needed to:

  1. Strip the RTF formatting to plain text.
  2. Add the date from the filename inside each TXT file as Date: May 16, 2017.
  3. Save them as TXT files (e.g., 5-16-17.txt) in /Users/daviddaniels/TXT_Files.
  4. Eventually combine them into one file (but that’s another story).

The First Attempt: A Solid Start

I kicked off with a Python script using striprtf to handle the RTF-to-text conversion. Here’s the base:

import os
from striprtf.striprtf import rtf_to_text

input_directory = "/Users/daviddaniels/RTF_Files"
output_directory = "/Users/daviddaniels/TXT_Files"

if not os.path.exists(output_directory):
os.makedirs(output_directory)

for filename in os.listdir(input_directory):
if filename.lower().endswith('.rtf'):
rtf_path = os.path.join(input_directory, filename)
datestamp = os.path.splitext(filename)[0] # "5-16-17"
with open(rtf_path, 'r', encoding='utf-8', errors='ignore') as rtf_file:
plain_text = rtf_to_text(rtf_file.read())
output_text = f"Datestamp: {datestamp}\n\n{plain_text}"
txt_filename = f"{datestamp}.txt"
txt_path = os.path.join(output_directory, txt_filename)
with open(txt_path, 'w', encoding='utf-8') as txt_file:
txt_file.write(output_text)
Python

This worked, producing 5-16-17.txt with Datestamp: 5-16-17 inside. But 5-16-17 wasn’t cutting it—I wanted May 16, 2017.

The Hiccup: Datestamp Drama

To fancy up the date, I added datetime to parse and reformat:

import os
from striprtf.striprtf import rtf_to_text

input_directory = "/Users/daviddaniels/RTF_Files"
output_directory = "/Users/daviddaniels/TXT_Files"

if not os.path.exists(output_directory):
os.makedirs(output_directory)

for filename in os.listdir(input_directory):
if filename.lower().endswith('.rtf'):
rtf_path = os.path.join(input_directory, filename)
datestamp = os.path.splitext(filename)[0] # "5-16-17"
with open(rtf_path, 'r', encoding='utf-8', errors='ignore') as rtf_file:
plain_text = rtf_to_text(rtf_file.read())
output_text = f"Datestamp: {datestamp}\n\n{plain_text}"
txt_filename = f"{datestamp}.txt"
txt_path = os.path.join(output_directory, txt_filename)
with open(txt_path, 'w', encoding='utf-8') as txt_file:
txt_file.write(output_text)
Python
from datetime import datetime
datestamp_raw = os.path.splitext(filename)[0] # "5-16-17"
datestamp = datetime.strptime(datestamp_raw, '%m-%d-%y').strftime('%m/%d/%Y') # "05/16/2017"
output_text = f"Datestamp: {datestamp}\n\n{plain_text}"
txt_filename = f"{datestamp}.txt"
Terminal

I ran it in Terminal:

bash

cd /Users/daviddaniels
python3 convert_rtf.py
Terminal

Boom—error: No such file or directory: ’05/16/2017.txt’. The slashes in 05/16/2017 made Python think I wanted directories (/Users/daviddaniels/TXT_Files/05/16/). Grok flagged this: filenames can’t have slashes. Back to the drawing board.

The Fix: Splitting the Datestamp

We needed two datestamps:

  • Inside the file: A pretty format like May 16, 2017.
  • Filename: Something slash-free like 5-16-17.

After some trial and error, I settled on keeping the filename raw (from the RTF) and reformatting only the content. Plus, I swapped “Datestamp” to “Date” because that is what DayOne was looking for. Here’s the winning script:

python

import os
from datetime import datetime
from striprtf.striprtf import rtf_to_text

input_directory = "/Users/daviddaniels/RTF_Files"
output_directory = "/Users/daviddaniels/TXT_Files"

if not os.path.exists(output_directory):
os.makedirs(output_directory)

for filename in os.listdir(input_directory):
if filename.lower().endswith('.rtf'):
rtf_path = os.path.join(input_directory, filename)
datestamp_raw = os.path.splitext(filename)[0] # "5-16-17"
datestamp = datetime.strptime(datestamp_raw, '%m-%d-%y').strftime('%B %d, %Y') # "May 16, 2017"
with open(rtf_path, 'r', encoding='utf-8', errors='ignore') as rtf_file:
plain_text = rtf_to_text(rtf_file.read())
output_text = f"Date: {datestamp}\n\n{plain_text}"
txt_filename = f"{datestamp_raw}.txt" # "5-16-17.txt"
txt_path = os.path.join(output_directory, txt_filename)
with open(txt_path, 'w', encoding='utf-8') as txt_file:
txt_file.write(output_text)
print(f"Converted: {filename} -> {txt_filename}")
Python

How to Implement This Fix

Want to try it yourself? Here’s the step-by-step:

  1. Install Python:
    • Check if you’ve got it: python3 –version in Terminal.
    • No dice? Grab it from python.org. On macOS, the installer’s a breeze—just follow the prompts.
  2. Install striprtf:
    • In Terminal:bashpip3 install striprtf
    • If that fails, try python3 -m pip install striprtf.
  3. Set Up Your Files:
    • Dump your RTF files into a folder (e.g., /Users/yourname/RTF_Files).
    • Create an output folder if it’s not there:bashmkdir /Users/yourname/TXT_Files
  4. Save the Script:
    • Open Terminal and launch TextEdit:bashopen -e /Users/yourname/convert_rtf.py
    • Paste the script above.
    • In TextEdit, hit Format > Make Plain Text (or Shift+Command+T).
    • Save and close. Replace yourname with your actual username (e.g., daviddaniels for me).
  5. Run It:
    • In Terminal:bashcd /Users/yourname python3 convert_rtf.py
    • Watch it churn out lines like:Converted: 5-16-17.rtf -> 5-16-17.txt Converted: 5-17-17.rtf -> 5-17-17.txt ...
  6. Check Your Work:
    • Peek at a file:bashhead /Users/yourname/TXT_Files/5-16-17.txt
    • You should see Date: May 16, 2017 followed by the text.

The Payoff

After running this, I had 1700+ TXT files, each with a nicely formatted Date: May 16, 2017-style header, all named safely like 5-16-17.txt. No more directory errors, no more ugly 5-16-17 inside the files—just clean, readable dates. Later, I even combined them into one file, but that’s a tale for another post.

Lessons Learned

  • Filenames Hate Slashes: Stick to dashes or underscores for file naming.
  • Datetime is Your Friend: strptime and strftime can morph any date format if you know the pattern.
  • Terminal + Python = Power: A few commands and a script can tame a thousand files.

Big thanks to Grok for spotting the slash issue and nudging me toward %B %d, %Y. Got a similar file-wrangling puzzle? Drop a comment—I’d love to hear how you’d tackle it!


Feel free to share...