0

我正在尝试将 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"
4

1 回答 1

0

你的分析是正确的。问题是脚本假定它extraction_subdir总是在downloadpath.

我无法亲自测试它,但我相信以下内容将解决该问题:

file="${downloadpath}/${file}"

它将强制文件路径是绝对的而不是相对的。

于 2014-10-21T15:17:26.217 回答