在批处理脚本中检查文件大小 [英] Checking file size in a batch script

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

问题描述

我正在尝试查找文件的大小,如果它大于0,我想做一些事情. 我有以下代码:

I am trying to find the size of a file and if it is greater than 0, I want to do some stuff. I have this code:

set file="C:\AnalyzerCheck\loaded.txt"
set minbytesize=0
if exist %file% (
FOR /F "usebackq" %A IN ('%file%') DO set size=%~zA
if %size% GTR %minbytesize% (
    //do stuff
) else (
    //do stuff
)

但是,运行脚本时出现此输出/错误:

However, I am getting this ouput/error when I run the script:

C:\ AnalyzerCheck>设置文件= C:\ AnalyzerCheck \ loaded.txt

C:\AnalyzerCheck>set file=C:\AnalyzerCheck\loaded.txt

C:\ AnalyzerCheck>设置minbytesize = 0

C:\AnalyzerCheck>set minbytesize=0

file〜zA出乎意料 时间.

file~zA was unexpected at this time.

C:\ AnalyzerCheck> FOR/F"usebackq"文件〜zA

C:\AnalyzerCheck>FOR /F "usebackq" file~zA

C:\ AnalyzerCheck>

C:\AnalyzerCheck>

如何解决此错误?

新错误:

推荐答案

此命令:

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

有两个错误:不能使用/F选项(都不是"useback"选项),因为您不想读取文件CONTENTS,而只处理文件NAME.另外,如果此命令位于批处理文件中,则A可替换参数必须具有两个百分号:

have two errors: You must not use /F option (neither "useback" option) because you want not to read the file CONTENTS, but just process the file NAME. Also, if this command is inside a Batch file, the A replaceable parameter must have two percent signs:

FOR %%A IN (%file%) DO set size=%%~zA

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

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