在已删除扩展名的图像文件上恢复正确的扩展名 [英] Reinstating the correct extension on image files where the extension was removed

查看:81
本文介绍了在已删除扩展名的图像文件上恢复正确的扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有30k +张图片,没有扩展名...

我使用一个名为GPRename的程序为我的每个图像取一个随机名称,因为某些名称很长,以至于引起问题,并且它删除了我所有图片的文件扩展名.现在,我在打开Windows计算机和手机上的图像时遇到了困难(Linux上没有问题)

I have 30k+ images without extensions...

I used a program called GPRename to give each of my images a random name, because some of the names were very long so they were causing problems, and it deleted the file extension on all my pictures. Now I'm having difficulty opening the images on my Windows computer and my phone (no prob on Linux)

我想知道是否有人可以使用可以在所有图像末尾添加正确文件扩展名的程序/脚本?我当时在考虑使用bash命令文件"的脚本,但是我对Bash不太满意,所以我不知道如何对多个文件执行此操作.

I was wondering if any of you know of a program/script I can use that would add the correct file extension to the end of all the images? I was thinking of a script using the bash command "file" but I'm not very good with Bash so I would have no idea how to do this for multiple files.

文件扩展名包括.jpg .png .gif .webm:

The file extensions include .jpg .png .gif .webm:

ssd006: JPEG image data, JFIF standard 1.01
ssdss078: PNG image data, 1920 x 1080, 8-bit/color RGB, non-interlaced
ssdss029: GIF image data, version 89a, 300 x 168
ssds008:  WebM

推荐答案

注意::我无法测试此代码,因此为了安全起见,目前该代码仅打印出 它将运行的命令.要实际运行它们,请删除 echo :

NOTE: I can't test this code, so for safety's sake, this currently just prints out the commands that it would run. To actually run them, delete the echo:

mkdir ../new
for f in *; do
    case `file "$f"` in
    *JPEG*) e=jpg ;;
    *GIF*) e=gif ;;
    *PNG*) e=png ;;
    *WebM*) e=webm ;;
    *) e=UNKNOWN ;;
    esac
    echo mv "$f" "../new/$f.$e"
done

任何无法识别的文件都将以 .UNKNOWN 扩展名.

Any files that it doesn't recognise will get an extension of .UNKNOWN.

这篇关于在已删除扩展名的图像文件上恢复正确的扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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