1

コマンドラインで特定のプロパティを選択するオプションをユーザーに提供しています。ユーザーがコンマ区切りのリストを選択したい。したがって、ユーザーには次のようなものが表示されます

  1. プロップ1
  2. プロップ2
  3. プロップ3

したがって、ユーザーは 1,3 を指定して Enter キーを押すと、1 と 3 のデータベースが作成されます。しかし、これらの Prop1、Prop2、Prop3 には一意の名前と ID があり、プロパティと同じバッチ スクリプトで指定したので、ユーザーが選択したオプションに応じてそれらすべてを連結し、ビルド スクリプトに渡します。

Example of properties:
SET propertyID1=11
SET propertyID2=12
SET propertyID3=13
SET propertyID4=14
SET propertyID5=15

SET propertyIDPref1=011
SET propertyIDPref2=012
SET propertyIDPref3=013
SET propertyIDPref4=014
SET propertyIDPref4=015

SET propertyName1=A
SET propertyName2=B
SET propertyName3=C
SET propertyName4=D
SET propertyName5=E

call :parse "%M%"

pause
goto :eof

:parse
setlocal
set list=%~1
for /F "tokens=1* delims=," %%f in ("%list%") do (
    if not "%%f" == "" call :getLineNumber %%f
    if not "%%g" == "" call :parse "%%g"
    if "%%g" == "" call :printPropertiesConcatenation
)

endlocal

goto :eof

:printPropertiesConcatenation
setLocal
    echo "Gr8 " %buildPropertiesList%
endLocal
goto :eof
:getLineNumber
setlocal
echo file name is %1
set propID = 'propertyID'%1%

set propStr=propertyID
set propID=%1
set newvar=!%propStr%%propID%!
echo %newvar%

set propNameStr=propertyName
set propName=!%propNameStr%%propID%!
echo %propName%

set propIDPrefix=propertyIDPref
set propIDPrefixWithPrefix=!%propIDPrefix%%propID%!
echo %propIDPrefixWithPrefix%

set buildPropertiesList=%buildPropertiesList%','!%propIDPrefix%%propID%!

goto :eof

繰り返しでこれらのプロパティから正しい値を読み取り、echo in loop を使用して確認できます。しかし、これらの値を連結してビルドスクリプトに渡したいです。しかし、1 つの変数にすべての連結された値を表示する方法がありません。

私はこのようなものが欲しいです。最後に propNames = A,C を設定し、propIds = 11,13 を設定して、propNames と PropIds を渡すことができるようにします。

上記のコードから、buildPropertiesList に 011,013 を持たせたい

何か方法はありますか

4

2 に答える 2

1

これはあなたのために働くかもしれません:

@ECHO OFF &SETLOCAL ENABLEDELAYEDEXPANSION
SET propertyID1=11
SET propertyID2=12
SET propertyID3=13
SET propertyID4=14
SET propertyID5=15

SET propertyIDPref1=011
SET propertyIDPref2=012
SET propertyIDPref3=013
SET propertyIDPref4=014
SET propertyIDPref4=015

SET propertyName1=A
SET propertyName2=B
SET propertyName3=C
SET propertyName4=D
SET propertyName5=E

for /f "tokens=1*delims==" %%a in ('set "property"') do (
    set "apx=%%a"
    set "apx=!apx:*property=!"
    for /f "delims=0123456789" %%b in ("!apx!") do set "apx=%%b"
    if defined props!apx! (
        call set "props!apx!=%%props!apx!%%,%%b"
    ) else (
        set "props!apx!=%%b"
    )
)
set "props"
于 2013-11-07T12:34:59.057 に答える
1

配列を使用すると、少ないコードでこの問題を解決できます。例えば:

@echo off
setlocal EnableDelayedExpansion

rem Create the arrays of properties:
set /A i=1, ID=11, IDPref=1011
for %%a in (A B C D E) do (
   SET propertyID[!i!]=!ID!
   SET propertyIDPref[!i!]=!IDPref:~-3!
   SET propertyName[!i!]=%%a
   set /A i+=1, ID+=1, IDPref+=1
)

echo Properties menu:
echo/
for /L %%i in (1,1,5) do echo %%i. !propertyName[%%i]!
echo/

set /P "M=Enter properties list: "
call :parse "%M%"
echo Names: !propNames:~0,-1!
echo Ids:   !propIds:~0,-1!
echo List:  !propList:~0,-1!

pause
goto :eof

:parse
set "propNames="
set "propIds="
set "propList="
for %%i in (%~1) do (
   set "propNames=!propNames!!propertyName[%%i]!,"
   set "propIds=!propIds!!propertyID[%%i]!,"
   set "propList=!propList!!propertyIDPref[%%i]!,"
)
exit /B
于 2013-11-07T14:36:39.120 に答える