仅解压缩特定扩展名 [英] unzip specific extension only

查看:111
本文介绍了仅解压缩特定扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含zip存档的目录,其中包含.jpg,.png,.gif图像.我想解压缩每个仅使用图像的档案文件,然后将其放入具有档案文件名称的文件夹中.

I have a a directory with zip archives containing .jpg, .png, .gif images. I want to unzip each archive taking the images only and putting them in a folder with the name of the archive.

所以:

files/archive1.zip
files/archive2.zip
files/archive3.zip
files/archive4.zip

打开archive1.zip-提取sunflower.jpg,rose_sun.gif.创建一个文件夹files/archive1/并将图像添加到该文件夹​​,因此,files/archive1/folder1.jpg,files/archive1/rose_sun.gif.对每个存档执行此操作.

Open archive1.zip - take sunflower.jpg, rose_sun.gif. Make a folder files/archive1/ and add the images to that folder, so files/archive1/folder1.jpg, files/archive1/rose_sun.gif. Do this to each archive.

我真的不知道该怎么做,欢迎提出所有建议.我有600多个档案,一个自动解决方案将是一个救生员,最好是Linux解决方案.

I really don't know how this can be done, all suggestions are welcome. I have over 600 archives and an automatic solution would be a lifesaver, preferably a linux solution.

推荐答案

类似的内容:

#!/bin/bash
cd ~/basedir/files
for file in *.zip ; do
    newfile=$(echo "${file}" | sed -e 's/^files.//' -e 's/.zip$//')
    echo ":${newfile}:"
    mkdir tmp
    rm -rf "${newfile}"
    mkdir "${newfile}"
    cp "${newfile}.zip" tmp
    cd tmp
    unzip "${newfile}.zip"
    find . -name '*.jpg' -exec cp {} "../${newfile}" ';'
    find . -name '*.gif' -exec cp {} "../${newfile}" ';'
    cd ..
    rm -rf tmp
done

这已经过测试,将处理文件名中的空格(zip文件和提取的文件).如果zip文件在不同目录中具有相同的文件名,则可能会发生冲突(如果要展平目录结构,则无法避免).

This is tested and will handle spaces in filenames (both the zip files and the extracted files). You may have collisions if the zip file has the same file name in different directories (you can't avoid this if you're going to flatten the directory structure).

这篇关于仅解压缩特定扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆