enter image description here我为我的项目编写了批处理脚本,因为路径包含空格,它不起作用。 你能帮我吗
@ECHO OFF
REM The below command will look for the size of file on the server and inform the user if scheduler is down.
setlocal
set nl=^& echo.
set file="C:\Program Files (x86)\Common Files\Zoom\Support\CptControl.exe"
set maxbytesize=0
FOR /F "usebackq" %%A IN ('%file%') DO set size=%%~zA
if %size% EQU %maxbytesize% (echo WARNING !!! %nl%Scheduler File is ^= %maxbytesize% bytes%nl%Please do not process invoices, contact Webcenter Support) else (echo Scheduler File OK)
PAUSE
答案 0 :(得分:1)
将引号置于值之外但保护asignment
set "file=C:\Program Files (x86)\Common Files\Zoom\Support\CptControl.exe"
for /f
无需读取文件大小,请使用简单的for
。也
请注意,未存储在%file%中的引号现在包含在命令
FOR %%A IN ("%file%") DO set "size=%%~zA"
只是会话捕获
测试代码
@echo off
setlocal enableextensions disabledelayedexpansion
set "file=C:\Program Files (x86)\Windows NT\Accessories\WordPad.exe"
echo File to process ------------------------------------------------------------
echo "%file%"
echo(
echo Data from dir command ------------------------------------------------------
dir "%file%" | findstr /r /c:"^[^ ]"
echo(
echo Data from for command ------------------------------------------------------
for %%a in ("%file%") do (
echo %%~fa : %%~za
set "size=%%~za"
)
echo Reported size: %size%
echo(
答案 1 :(得分:0)
首先,您可以将路径设置为不带引号,然后稍后引用它:
set filepath=C:\Program Files (x86)\Common Files\Zoom\Support
并在%
"%filepath%\CptControl.exe"
或带空格的文件名
"%filepath%\Cpt Control.exe"