2012-02-21 6 views
0

私は基本的に変数がバッチファイルにどれくらいあるかをテストする必要があります。例:varの長さをバッチでテストするにはどうすればよいですか?

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

は、だから私は

Batch files 

を入力した場合、それは@minitechによって提供されたリンクに基づいて

someVar is 10 characters long. 
+0

私はバッチスクリプタではありませんが、Googleはこれを提供しています:http:// fo rums.afterdawn.com/thread_view.cfm/514228 – Ryan

+2

文字列「バッチファイル」は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