【问题标题】:How can I find out a files “mime-type(Content-Type?)”? on Windows如何找到文件“mime-type(Content-Type?)”?在 Windows 上
【发布时间】:2015-12-04 06:41:51
【问题描述】:

有没有办法在 windows batch/PowerShell 中找出文件的 MIME-TYPE(或者称为“Content-Type”...)?

【问题讨论】:

标签: windows batch-file content-type


【解决方案1】:

虽然不是直接在 Windows 命令提示符中,但更现代的方法是使用 Git for Windows。安装后,运行git-bash 和命令file path\to\file。一个示例输出可能是:

TestFile.ico: MS Windows icon resource - 1 icon, 128x128, 32 bits/pixel

或者,使用命令file -i path\to\file 可能会给出:

TestFile.ico: image/vnd.microsoft.icon; charset=binary

【讨论】:

  • 谢谢!至少我可以获取 mime 类型并构造一个mv 批处理来修复文件扩展名。也许有更多时间的人可以自动化这个过程:)
  • 很好的答案。不需要下载任何东西,因为我已经安装了 git。
【解决方案2】:

使用File from source 或者您可以使用get win32 binaries from here

空文件示例:

COPY NUL >test.ext && "C:\Program Files (x86)\GnuWin32\bin\file" −-mime-type test.ext

这将返回:

test.ext; text/plain

更新:

另外,-b--brief 不要在输出行前添加文件名

file -b −-mime-type test.ext 仅返回 mime 类型:text/plain

输入 file --help 了解更多选项

注意:源比 GnuWin32 提供给我们的可执行文件更新得多。

【讨论】:

    猜你喜欢
    • 2011-01-14
    • 2016-02-27
    • 2011-05-12
    • 1970-01-01
    • 2010-11-13
    • 1970-01-01
    • 2017-01-24
    • 1970-01-01
    • 2011-09-10
    相关资源
    最近更新 更多