如何在 Windows 批处理脚本中检查文件的大小? [英] How can I check the size of a file in a Windows batch script?

查看:59
本文介绍了如何在 Windows 批处理脚本中检查文件的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个批处理文件来检查文件的 filesize 是什么.

I want to have a batch file which checks what the filesize is of a file.

如果它大于 %somy% kbytes, 它应该使用 GOTO 重定向到其他地方.

If it is bigger than %somany% kbytes, it should redirect with GOTO to somewhere else.

示例:

[check for filesize]
IF %file% [filesize thing Bigger than] GOTO No
echo Great! Your filesize is smaller than %somany% kbytes.
pause
exit
:no
echo Um... You have a big filesize.
pause
exit

推荐答案

如果把文件名作为批处理文件的参数,你只需要%~z1(1表示第一个参数)

If the file name is used as a parameter to the batch file, all you need is %~z1 (1 means first parameter)

如果文件名不是参数,你可以这样做:

If the file name is not a parameter, you can do something like:

@echo off
setlocal
set file="test.cmd"
set maxbytesize=1000

FOR /F "usebackq" %%A IN ('%file%') DO set size=%%~zA

if %size% LSS %maxbytesize% (
    echo.File is ^< %maxbytesize% bytes
) ELSE (
    echo.File is ^>= %maxbytesize% bytes
)

这篇关于如何在 Windows 批处理脚本中检查文件的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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