Add some placeholder text for all empty files

import os

# Specify your Obsidian vault directory here
obsidian_vault_directory = '/path/to/your/obsidian/directory'

# Specify the text you want to add to the empty files
replacement_text = 'Your replacement text'

# Iterate over each file in the directory
for root, dirs, files in os.walk(obsidian_vault_directory):
    for file in files:
        # If the file is a markdown file
        if file.endswith('.md'):
            file_path = os.path.join(root, file)
            # Open the file and check if it's empty
            with open(file_path, 'r+') as f:
                contents = f.read()
                # If the file is empty, write the replacement text
                if not contents.strip():
                    print(file_path)
                    # Print the filename
                    # Print the path

Add some placeholder text for all empty files

import os

# Specify your Obsidian vault directory here
obsidian_vault_directory = '/path/to/your/obsidian/directory'

# Specify the text you want to add to the empty files
replacement_text = 'Your replacement text'

# Iterate over each file in the directory
for root, dirs, files in os.walk(obsidian_vault_directory):
    for file in files:
        # If the file is a markdown file
        if file.endswith('.md'):
            file_path = os.path.join(root, file)
            # Open the file and check if it's empty
            with open(file_path, 'r+') as f:
                contents = f.read()
                # If the file is empty, write the replacement text
                if not contents.strip():
                    f.seek(0)
                    f.write(replacement_text)
                    f.truncate()

Referenced in:

All notes