문제

File path like this: path/path/path/File name 2.3.pdf.zip

What am I doing wrong:

# unzip files back to normal
# and remove zip files
for f in `find "$1" -type f -iname "*.zip"`; do
        dir=`dirname "$f"`
        unzip -o "$f" -d "$dir"
        rm -f "$f"
done

Error message: unzip: cannot find or open file, file.zip, or file.ZIP

Using UnZip 5.52 Red Hat Enterprise Linux Server release 5.10 (Tikanga)

도움이 되었습니까?

해결책

I think your loop is splitting up the output of find based on the spaces. You may want to do something to read one line at a time, like this

find "$1" -type f -iname "*.zip" | while read f
do
    dir=`dirname "$f"`
    unzip -o "$f" -d "$dir"
    rm -f "$f"
done

Or, alternatively, you could set IFS:

IFS='\n'
for f in `find "$1" -type f -iname "*.zip"`; do
        dir=`dirname "$f"`
        unzip -o "$f" -d "$dir"
        rm -f "$f"
done

다른 팁

Perhaps your problem is here

dir=`dirname $f`

Try instead

dir=`dirname "$f"`

Also, you have some unnecessary semicolons at the end of a few of your lines.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top