You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
report_app/doc2docx.sh

40 lines
1.1 KiB
Bash

#!/bin/bash
# 设置监听的目标文件夹
TARGET_DIR="/app/temp_uploads"
while true; do
# 检查文件夹是否存在
if [ ! -d "$TARGET_DIR" ]; then
exit 1
fi
# 查找文件夹下所有的 .doc 文件
doc_files=$(find "$TARGET_DIR" -type f -name "*.doc")
# 若找到 .doc 文件,则进行转换
if [ -n "$doc_files" ]; then
for doc_file in $doc_files; do
# 获取不带扩展名的文件名
base_name="${doc_file%.*}"
# 生成对应的 .docx 文件路径
docx_file="${base_name}.docx"
# 使用 soffice 进行转换
soffice --headless --convert-to docx "$doc_file" --outdir "$TARGET_DIR"
# 检查转换是否成功
if [ -f "$docx_file" ]; then
# 转换成功,删除原有的 .doc 文件
rm "$doc_file"
echo "已将 $doc_file 转换为 $docx_file 并删除原文件。"
sleep 3
else
echo "转换 $doc_file 失败。"
fi
done
fi
done