将CD刻录到目录

时间:2014-10-21 15:11:28

标签: bash unrar torrent

我正在尝试将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文件放在目录中: /家庭/用户/下载/ tcomplete / FOLDERNAME /

我在看:

file=$(basename "$file")
...
file="../$file"

作为崇拜者但不确定如何解决这个问题。

编辑:

解决了这个问题,我在unrar命令中指定了输出,例如:

${commands[$format]} "$file" "$extractedpath"

成为:

${commands[$format]} "$file" "/home/user/extract"

1 个答案:

答案 0 :(得分:0)

你的分析是正确的。问题是该脚本假定extraction_subdir始终在downloadpath内。

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

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

它会强制文件路径为绝对路径而不是相对路径。