#!/bin/bash # Check if a directory path is provided if [ "$#" -ne 1 ]; then echo "Usage: $0 " exit 1 fi # Get the directory path from the argument dir_path=$1 # Check if the specified directory exists if [ ! -d "$dir_path" ]; then echo "Directory does not exist: $dir_path" exit 1 fi # Iterate through all .docx files in the specified directory for docx_file in "$dir_path"/*.docx; do # Skip if no .docx files are found if [ ! -f "$docx_file" ]; then continue fi # Extract filename without extension filename=$(basename -- "$docx_file") filename="${filename%.*}" # Define the output Markdown filename md_file="${dir_path}/${filename}.md" # Convert the document to Markdown format pandoc -t markdown --extract-media="$dir_path" "$docx_file" -o "$md_file" echo "Converted: $docx_file to $md_file" done echo "Conversion complete."