Created
July 6, 2025 15:11
-
-
Save noflcl/04940cab8ff50efbc4985e9afd4724e1 to your computer and use it in GitHub Desktop.
Watch directory for new .docx files, convert to markdown and delete source file if successful
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Set the source and destination directories | |
| SRC_DIR=/path/to/source | |
| DST_DIR=/path/to/destination | |
| # Create the destination directory if it doesn't exist | |
| mkdir -p "$DST_DIR" | |
| # Watch the source directory for new .docx files | |
| inotifywait -m -r -e create "$SRC_DIR" | | |
| while read -r directory events filename; do | |
| # Check if the new file is a .docx file | |
| if [[ "$filename" =~ \.docx$ ]]; then | |
| # Convert the .docx file to md using pandoc | |
| pandoc -o "$DST_DIR/${filename%.docx}.md" "$directory$filename" | |
| # Check if the md conversion was successful | |
| if [ $? -eq 0 ]; then | |
| # Delete the source .docx file | |
| rm "$directory$filename" | |
| else | |
| echo "Error converting $filename to markdown" | |
| fi | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment