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

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

问题描述

我想有哪些检查什么文件大小是一个文件的批处理文件。

如果它比%somany%字节,大它应该GOTO重定向到别的地方去。

例如:

  [检查文件大小]
IF%文件%[文件大小事莫过于更大] GOTO无
回声太好了!您的文件大小超过%somany%字节小。
暂停
出口
:没有
回声嗯...你有一个大的文件大小。
暂停
出口


解决方案

如果文件名作为参数传递给批处理文件,你需要的是%〜Z1 (1表示第一个参数)

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

 关闭@echo
SETLOCAL
设置文件=TEST.CMD
设置maxbytesize = 1000FOR / F有usebackq%% A IN('%文件%')不要设置大小= %%〜ZA如果大小%LSS%%maxbytesize%(
    echo.File是^< %maxbytesize%字节
)ELSE(
    echo.File是^> =%maxbytesize%字节

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

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

Example:

[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

解决方案

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天全站免登陆