是否可以使用批处理文件检测文件格式和文件编码?
是否可以使用批处理文件检测文件格式和文件编码?如果特定文件不符合预期格式,会抛出错误吗?
Is it possible to detect file format and encoding of file using batch files? And if a particular file is not of intended format, throw an error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
作为一个 *nix 人,我想要跳到比批处理文件更强大的东西,比如 Python。 (或者 shell 脚本,但我假设您使用的是 Windows --- 您可能会研究 PowerShell,但我从未尝试过。)
Unix 对于此类事情有一个很棒的实用程序,它的名称是
文件
。这里似乎有一个 Windows 版本:http://gnuwin32.sourceforge.net/packages/file。 htm基本上,您运行
file [your filename here]
并且file
吐出有关该文件的简介。例如:它并不总是正确的,并且并不意味着如果
file
说“这是一个 JPEG”,该文件实际上是一个 JPEG:它可能已损坏,等等。另外,如果我将上面的 7z 存档重命名为“foo”:
...
file
仍然会得到它。As a *nix guy, I'd want to jump for something more powerful than a batch file, such as Python. (or a shell script, but I'm assuming you're using Windows --- you might look into PowerShell, but I've never tried it.)
Unix has a great utility for this sort of thing, it's named
file
. There appears to be a Windows version here: http://gnuwin32.sourceforge.net/packages/file.htmBasically, you run
file [your filename here]
andfile
spits out a blurb about the file. For example:It's not always right, and it doesn't mean that if
file
says "this is a JPEG" that the file is actually a JPEG: it could be corrupt, etc.Also, if I rename the above 7z archive to "foo":
...
file
will still get it.