2016-09-29 125 views
-1

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 

回答

1

将报价出来的价值,但保护asignment

set "file=C:\Program Files (x86)\Common Files\Zoom\Support\CptControl.exe" 

没有必要for /f读取文件的大小,使用简单for。此外 记不存储在%文件%引号现在都包含在命令

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

只是一个会话捕获

Capture of a test code

测试代码

@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(
+0

它没有为我工作用它在下面,有没有它是文件路径中的任何其他的解决办法有空间 – suvarna

+0

@ suvarna,对不起,但是,没有工作'是什么意思? **如何**不起作用?观察到的行为是什么?它与预期的行为有什么不同? –

+0

理想情况下,它必须读取文件大小,并且必须与逻辑中提供的大小进行比较,如果我的文件路径没有空格,则我在脚本中提供的逻辑正在工作。 – suvarna

0

首先,可以将路径设置为不加引号,然后稍后引用它:

set filepath=C:\Program Files (x86)\Common Files\Zoom\Support 

%之间

"%filepath%\CptControl.exe" 

或文件名称用空格

"%filepath%\Cpt Control.exe" 
+0

@ECHO OFF REM以下命令将查找服务器上的文件大小,并通知用户计划程序是否已关闭。 setlocal set nl = ^&echo。 组文件路径= C:\程序文件(x86)\共同文件\缩放\支持 “%文件路径%\ CptControl.exe” 组maxbytesize = 0 FOR/F “有usebackq” %% A IN( '%file%')DO set size = %%〜zA if%size%EQU%maxbytesize%(echo WARNING !!!%nl%Scheduler File是^ =%maxbytesize%bytes%nl%请勿处理发票,联系Webcenter支持)else(echo Scheduler File OK) – suvarna

+0

set filepath = C:\ Program Files文件(x86)\ Common Files \ Zoom \支持 “%filepath%\ CptControl.exe” – suvarna

+0

我尝试了你所说的,没有得到输出 – suvarna

相关问题