在批处理脚本中检查文件大小

发布于 2024-12-11 19:30:02 字数 611 浏览 0 评论 0原文

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

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
)

但是,当我运行脚本时,我收到此输出/错误:

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

C:\AnalyzerCheck>设置 minbytesize=0

file~zA 对此感到意外 时间。

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

C:\AnalyzerCheck>

我该如何修复这个错误?

编辑:

新错误:

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>set file=C:\AnalyzerCheck\loaded.txt

C:\AnalyzerCheck>set minbytesize=0

file~zA was unexpected at this
time.

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

C:\AnalyzerCheck>

How do I fix this error?

Edit:

New error:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

哽咽笑 2024-12-18 19:30:02

此命令:

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

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

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

This command:

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

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
一向肩并 2024-12-18 19:30:02

在脚本中,

此命令:

    for /f %%A in ("myfile.txt") do set size=%%~zA

或此命令:

    set "filename=myfile.txt"
    for %%A in (%filename%) do echo.Size of "%%A" is %%~zA bytes

或此命令:

    set "filename=myfile.txt"
    for /f %%A in (%filename%) do set size=%%~zA

Within a script,

This Command:

    for /f %%A in ("myfile.txt") do set size=%%~zA

Or This Command:

    set "filename=myfile.txt"
    for %%A in (%filename%) do echo.Size of "%%A" is %%~zA bytes

Or This Command:

    set "filename=myfile.txt"
    for /f %%A in (%filename%) do set size=%%~zA
清晨说晚安 2024-12-18 19:30:02
@echo off
cd C:\MyFolder\
set file="MyFile.txt"

set maxbytesize=0

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

if %size% GTR %maxbytesize% (
    //do stuff
) ELSE (
    //do stuff
)
@echo off
cd C:\MyFolder\
set file="MyFile.txt"

set maxbytesize=0

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

if %size% GTR %maxbytesize% (
    //do stuff
) ELSE (
    //do stuff
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文