Skip to content

Commit

Permalink
Generate an import script for gatsby, script generated with ChatGPT
Browse files Browse the repository at this point in the history
Prompt for ChatGPT:

> create a script that moviles `index.md` files that are stored inside a `pages` folder, but rename the destination file to have the name of the containing folder
  • Loading branch information
jackbravo committed May 8, 2023
1 parent 898802f commit 6698a9f
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions import_blog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import shutil

# Specify the path to the directory containing the "pages" folder
root_directory = "/path/to/root/directory"

# Define a function to move index.md files and rename them
def move_index_files(root_directory):
# Navigate to the "pages" folder
pages_directory = os.path.join(root_directory, "pages")
os.chdir(pages_directory)

# Loop through all directories in the "pages" folder
for directory in os.listdir():
# Check if the current item is a directory
if os.path.isdir(directory):
# Check if the directory contains an "index.md" file
index_file = os.path.join(directory, "index.md")
if os.path.isfile(index_file):
# Determine the new filename based on the directory name
new_filename = f"{directory}.md"

# Move and rename the file
destination_file = os.path.join(root_directory, new_filename)
shutil.move(index_file, destination_file)

# Call the function
move_index_files(root_directory)

0 comments on commit 6698a9f

Please sign in to comment.