我正在尝试将 extract_sudir 更改为与文件位置完全无关的路径(/home/user/downloads/tcomplete/foldername/file.mp4
#!/bin/bash
formats=(zip rar)
commands=([zip]="unzip -u" [rar]="unrar -o- e")
extraction_subdir='extracted'
downloadid=$1
downloadname=$2
downloadpath=$3
log()
{
logger -t deluge-extractarchives "$@"
}
log "Download complete: $@"
cd "${downloadpath}"
for format in "${formats[@]}"; do
while read file; do
log "Extracting \"$file\""
cd "$(dirname "$file")"
file=$(basename "$file")
# if extraction_subdir is not empty, extract to subdirectory
if [[ ! -z "$extraction_subdir" ]] ; then
mkdir "$extraction_subdir"
cd "$extraction_subdir"
file="../$file"
fi
${commands[$format]} "$file"
done < <(find "$downloadpath/$downloadname" -iname "*.${format}" )
done
我认为这很简单:
extraction_subdir='/home/user/extracted'
然而,这似乎只是将 unrar'd 文件放在目录中:/home/user/downloads/tcomplete/foldername/
我在看:
file=$(basename "$file")
...
file="../$file"
作为罪魁祸首,但不确定如何解决这个问题。
编辑:
我在 unrar 命令中指定输出解决了这个问题,例如:
${commands[$format]} "$file" "$extractedpath"
变成:
${commands[$format]} "$file" "/home/user/extract"