检查前4个字节并重命名文件扩展名的方法 [英] Method to inspect first 4 bytes and rename file extension

查看:90
本文介绍了检查前4个字节并重命名文件扩展名的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一大堆各种各样的文件,都缺少文件扩展名.

I have a large batch of assorted files, all missing their file extension.

我当前正在使用Windows 7 Pro.我能够打开"并尝试确定哪个应用程序打开了这些文件,然后手动重命名以适合.

I'm currently using Windows 7 Pro. I am able to "open with" and experiment to determine what application opens these files, and rename manually to suit.

但是,我希望使用某种方法来识别正确的文件类型(通常为PDF,其他方法包括JPG,HTML,DOC,XLS和PPT),然后批量重命名以添加适当的文件扩展名.

However I would like some method to identify the correct file type (typically PDF, others include JPG, HTML, DOC, XLS and PPT), and batch rename to add the appropriate file extension.

我能够使用记事本打开一些文件并查看前四个字节,在某些情况下,该字节显示为%PDF".

I am able to open some files with notepad and review the first four bytes, which in some cases shows "%PDF".

我认为一个小的脚本将能够检查这些字节,并根据需要进行重命名.但是,并非所有文件都提供了这样一种简单的方法. HTML,JPG,DOC等似乎没有提供这样的简单标识符.

I figure a small script would be able to inspect these bytes, and rename as appropriate. However not all files give such an easy method. HTML, JPG, DOC etc do not appear to give such an easy identifier.

此Powershell方法似乎已关闭: https://superuser .com/questions/186942/renaming-multiple-file-extensions-on-a-condition

This Powershell method appears to be close: https://superuser.com/questions/186942/renaming-multiple-file-extensions-based-on-a-condition

这里的难点在于该方法只能处理没有扩展名的文件类型;然后如何处理没有前四个字节标识符的文件?

Difficulty here is focusing the method to work on file types with no extension; and then what to do with the files that don't have the first four bytes identifier?

感谢任何帮助!

使用TriD的解决方案,请参见此处: http://mark0.net/soft-trid -e.html 以及使用Powershell在此处执行TriD的递归方法: http://mark0.net/forum/index.php?topic = 550.0

Solution using TriD seen here: http://mark0.net/soft-trid-e.html And recursive method using Powershell to execute TriD here: http://mark0.net/forum/index.php?topic=550.0

推荐答案

您可能可以通过获取Windows的file实用程序来节省一些时间(请参阅

You could probably save some time by getting a file utility for Windows (see What is the equivalent to the Linux File command for windows?) and then writing a simple script that maps from file type to extension.

该页面上提到的 TriD实用工具你想开箱即用;参见-ae和-ce选项)

Looks like the TriD utility that's mentioned on that page can do what you want out of the box; see the -ae and -ce options)

这篇关于检查前4个字节并重命名文件扩展名的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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