Reputation: 7
I wrote batch script for my project, as the path contains space, it's not working.
Could you please help me?
@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
Upvotes: 0
Views: 9414
Reputation: 70941
Place quotes out of the value but protecting the asignment
set "file=C:\Program Files (x86)\Common Files\Zoom\Support\CptControl.exe"
There is no need for for /f
to read the file size, use a simple for
. Also
note the quotes not stored in %file% are now included in the command
FOR %%A IN ("%file%") DO set "size=%%~zA"
Just a session capture
The 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(
Upvotes: 4
Reputation: 4903
First, you can set the path as unquoted and then just quote it later:
set filepath=C:\Program Files (x86)\Common Files\Zoom\Support
and use it in below in between %
"%filepath%\CptControl.exe"
or file name with spaces
"%filepath%\Cpt Control.exe"
Upvotes: 1