File size: 920 Bytes
9021b39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash

# Check if a directory path is provided
if [ "$#" -ne 1 ]; then
    echo "Usage: $0 <directory_path>"
    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."