文件类型 - 获取原始扩展名
如果文件已重命名,如何查找文件扩展名? 有没有可用的工具?
示例:我有一个文件“1.doc”;我希望大家知道这是一个我刚刚重命名为“1.txt”的Word文档。但该文件原本是Word文档;如何获得原始文件扩展名?
How to find file extension if the file has been renamed?
Is there any tool are available for this?
Example: I have a file "1.doc"; I hope everybody know this is a Word document I just renamed as "1.txt". But the file is a Word document originally; how can I get the original file extension?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当然可以:)
这是适合您的 C# 代码。我想你可以构建自己的工具;)
你可以使用此代码获得 mimetype。要找到 mime-type 的扩展名,只需进行一些谷歌搜索即可。
Of Course You can :)
This is the C# code for you. I guess you can bulid your own tool ;)
You get the mimetype using this code. To find the extension from mime-type just do a little google search.
不可能的。如果您使用的是 *nix 类型系统,请使用 file 命令来确定文件格式。
如果您真的对发生这样的事情感到偏执(并扰乱您的工作流程),您可以做两件事:
这将通过以下几种方式保护您:
哈希将确保您的文件没有被更改。
时间戳会告诉您上次修改的时间。
该扩展名会告诉您其原始扩展名。
由于仅重命名文件的扩展名不会修改其时间戳,因此您需要步骤 3。
使用此类技术将在 99.99999999999% 的情况下告诉您您的文件已被某物或某人修改。
Impossible. If you're on a *nix type system, use the file command to determine file format.
If you're really paranoid about stuff like this happening (and messing up your workflow), you can do 2 things:
This will guard you in few ways:
The hash will make sure your file hasn't been changed.
The timestamp will tell you the last time it was modified.
The extension will tell you its original extension.
Since just renaming file's extension won't modify its timestamp, you need step 3.
Using techniques like this will tell you in 99.99999999999% cases that your file has been modified by something or somebody.
你不能。您必须使用像
file
这样的工具来尝试检测文件的格式。You can't. You'd have to use a tool like
file
to try and detect the file's format.