#!/bin/bash
# 检查是否安装了dialog
if ! command -v dialog &> /dev/null; then
echo "请安装dialog工具: sudo apt-get install dialog"
exit 1
fi
# 设置参数
TARGET_DIR=$1
LOG_DIR="./日志"
LOG_FILE="$LOG_DIR/cleanup_log.txt"
RESTORE_FILE="$LOG_DIR/restore_log.txt"
# 创建日志文件夹
mkdir -p "$LOG_DIR"
# 创建菜单
dialog --title "清理工具" --menu "请选择操作:" 15 50 2 \
1 "清理空文件和文件夹" \
2 "恢复已删除项目" 2>tempfile
choice=$(<tempfile)
rm tempfile
case $choice in
1)
# 清理空白文件和文件夹
dialog --title "清理中" --infobox "开始清理 $TARGET_DIR ..." 5 50
find "$TARGET_DIR" -type f -empty -print -delete >> "$LOG_FILE"
find "$TARGET_DIR" -type d -empty -print -delete >> "$LOG_FILE"
dialog --title "完成" --msgbox "清理完成." 5 50
;;
2)
# 恢复功能
dialog --title "恢复操作" --infobox "恢复已删除项目中..." 5 50
while IFS= read -r line; do
if [[ "$line" =~ ^([^ ]+) ]]; then
mkdir -p "$(dirname "$line")"
touch "$line"
fi
done < "$RESTORE_FILE"
dialog --title "完成" --msgbox "恢复完成." 5 50
;;
*)
dialog --title "错误" --msgbox "无效选择." 5 50
;;
esac
```