How do I add comments from a text-file to an array of folders?

Hello everyone -

I was just wondering, as I’ve ventured out on bit of a limp here, if anyone have any experience with automating the process of creating folders in macOSX, and in the same process, adding individual comments to each of the folders?

I’ve managed to write the code that creates each of the folders, based on an external txt-file. Now, I want another external txt-file to be the basis of each comment/description that I want to add to each of the created folders.

I feel like I’ve tried everything. Maybe I am getting at this the wrong way … any help or suggestions are very much welcome!!

Thanks in advance.

Claus

import os
import xattr
from osxmetadata import *

folderstextfile = '/Users/clausneergaard/Dropbox/Projekter/21-01 Revit families, dokumentation/Folders (empty)/FoldersList.txt'
rootfolder = '/Users/clausneergaard/Dropbox/Projekter/21-01 Revit families, dokumentation/Folders (empty)/Folders'
metadata = '/Users/clausneergaard/Dropbox/Projekter/21-01 Revit families, dokumentation/Folders (empty)/FoldersMeta.txt'

# Open the file containing the list of names for each folder
with open(folderstextfile, 'r') as f:
  
  # Read the names from the file, one name per line
  names = f.read().splitlines()

# Open the file containing the list of descriptions for each folder
with open(metadata, 'r') as m:
  
  # Read the meta-data from the file, one piece of data per line
  meta = m.read().splitlines()

# Create a folder for each name in the list, and also add a comment to each folder in the list
for name in names:
  
  folders = os.makedirs(os.path.join(rootfolder, name))
  osxmetadata.MDItemSetAttribute("This is a comment", "Description")
  comments = xattr.setxattr('Folders', 'Comments', meta)