2012-02-21 3 views
0

기본적으로 변수가 배치 파일에 얼마나 오래 있는지 테스트해야합니다. 예 : 나는어떻게 var의 길이를 일괄 테스트합니까?

Batch files 

를 입력하면 그래서

@echo off 
set /p someVar="" 
//some code to figure out how long it is 
cls 
echo someVar is %length% characters long. 
pause 
exit 

는 말할 것이다

@minitech에서 제공하는 링크를 기반으로
someVar is 10 characters long. 
+0

나는 배치 스크립트가 아니지만 Google은 다음과 같이 제공합니다. http : // fo rums.afterdawn.com/thread_view.cfm/514228 – Ryan

+2

"Batch files"문자열의 길이가 11 문자가 아닌가요? –

답변

1

, 여기에 작동해야하는 스크립트입니다 :

@echo off 
set /p someVar="" 

::some code to figure out how long it is 

::Start by writing the file to a temp file 
echo %someVar%>"%temp%\tmp.txt" 

:: get the files size in bytes and subtract 3 for the trailing space and newline and delete the temp file 
for %%a in (%temp%\tmp.txt) do set /a length=%%~za & set /a length -=3 & del "%temp%\tmp.txt" 

cls 

echo someVar is %length% characters long. 

pause 

exit 
관련 문제