以下批处理文件适用于前10个选项。但是我不知道如何扩展批处理文件的功能超过10个选项0-9。我有35个可能的选项。
@ECHO OFF
MODE CON:COLS=100 LINES=50
SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION
(SET sourceFolder=C:\Users\Administrator\Desktop\test)
](SET targetFolder=C:\Users\Administrator\Desktop\test2)
SET /P "customerID=Enter Customer ID: "
:MENU
CLS
ECHO=
ECHO= ..................................................
ECHO= PLEASE SELECT THE OPTION FROM THE EVENT MENU BELOW
ECHO= ..................................................
ECHO Option Number Event Number Event Name
ECHO.
ECHO. 0. 101 NewCustomer
ECHO. 1. 102 ExisingCustomer
ECHO. 2. 103 LockedAccount
ECHO. 3. 104 DeleteAccount
ECHO. 4. 105 ExpireSession
ECHO. 5. 106 PasswordUpdated
ECHO. 6. 107 PasswordReset
ECHO. 7 108 HackedAccount
ECHO. 8. 109 UpdateProfile
ECHO. 9. 110 UpdateLists
ECHO. A. 111 NewPurchase
ECHO. B. 112 ExisingSale
ECHO. C. 113 AmendOrder
ECHO. D. 114 AmendDelivery
ECHO. E. 115 CancelOrder
ECHO. F. 116 OvernightFiles
ECHO. G. 117 DailyFiles
ECHO. H. 118 HelpFlies
ECHO. I. 119 FraudAccount
ECHO. J. 120 DeadCustomer
ECHO. K. 121 WelcomeEmail
ECHO. L. 122 OrderEmail
ECHO. M. 123 OrderAmmended
ECHO. N. 124 NoRemainingStock
ECHO. O. 125 ReplenishStock
ECHO. P. 126 SalesQuery
ECHO. Q. 127 UpdateFirstName
ECHO. R. 128 UpdateSurname
ECHO. S. 129 UpdateAddress
ECHO. T. 130 UpdateDateOfBirth
ECHO. U. 131 UpdateContactNo
ECHO. V. 132 UpdateEmail
ECHO. W. 133 UpdatePreferences
ECHO. X. 134 UpdateEmailPreferences
ECHO. Y. 135 UpdateBankDetails
CHOICE /C 0123456789ABCDEFGHIJKLMNOPQRSTUVWXY /M "CHOOSE AN OPTION"
SET "Option=%ERRORLEVEL%"
FOR /F "TOKENS=1-4 DELIMS=. " %%A IN ('FINDSTR/BC:"ECHO. " "%~f0"'
) DO IF "%%B"=="%Option%" (SET "Name=%%C" & SET "Code=%%D")
FOR /F "DELIMS=" %%A IN (
'FINDSTR/MISC:"%customerID%" "%sourceFolder%\*"^|FINDSTR/MIF:/ /C:"%Name%"'
) DO COPY "%%A" "%targetFolder%"
PAUSE
答案 0 :(得分:1)
花了一些时间来了解你的问题:
当您键入选项时,您将获得所选内容的索引而不是相关字母,如果不是0-9,则无法链接回菜单中的所选项目。
所以我建议将你的索引转换回输入的字母,如下所示(摘录):
module.js:471
throw err;
^
Error: Cannot find module './src/init'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/Blain/Desktop/ReactNative/RNScrollView/node_modules/gulp-sourcemaps/index.js:4:9)
at Module._compile (module.js:570:32)
at Module._extensions..js (module.js:579:10)
at Object.require.extensions.(anonymous function) [as .js] (/Users/Blain/Desktop/ReactNative/RNScrollView/node_modules/babel-register/lib/node.js:152:7)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
完整的测试代码,按下数字或字母打印字母和代码&amp;菜单标题:
SET "Option=%ERRORLEVEL%" <== this is your code
rem here scan for correct letter
FOR /L %%a IN (0,1,35) DO if %%a==%Option% set idx=%%a
rem small correction of index
set /A idx-=1
set Option=!Choice:~%idx%,1!
注意:
@echo off
set CHOICE=0123456789ABCDEFGHIJKLMNOPQRSTUVWXY
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
:MENU
CLS
ECHO=
ECHO= ..................................................
ECHO= PLEASE SELECT THE OPTION FROM THE EVENT MENU BELOW
ECHO= ..................................................
ECHO Option Number Event Number Event Name
ECHO.
ECHO. 0. 101 NewCustomer
ECHO. 1. 102 ExisingCustomer
ECHO. 2. 103 LockedAccount
ECHO. 3. 104 DeleteAccount
ECHO. 4. 105 ExpireSession
ECHO. 5. 106 PasswordUpdated
ECHO. 6. 107 PasswordReset
ECHO. 7 108 HackedAccount
ECHO. 8. 109 UpdateProfile
ECHO. 9. 110 UpdateLists
ECHO. A. 111 NewPurchase
ECHO. B. 112 ExisingSale
ECHO. C. 113 AmendOrder
ECHO. D. 114 AmendDelivery
ECHO. E. 115 CancelOrder
ECHO. F. 116 OvernightFiles
ECHO. G. 117 DailyFiles
ECHO. H. 118 HelpFlies
ECHO. I. 119 FraudAccount
ECHO. J. 120 DeadCustomer
ECHO. K. 121 WelcomeEmail
ECHO. L. 122 OrderEmail
ECHO. M. 123 OrderAmmended
ECHO. N. 124 NoRemainingStock
ECHO. O. 125 ReplenishStock
ECHO. P. 126 SalesQuery
ECHO. Q. 127 UpdateFirstName
ECHO. R. 128 UpdateSurname
ECHO. S. 129 UpdateAddress
ECHO. T. 130 UpdateDateOfBirth
ECHO. U. 131 UpdateContactNo
ECHO. V. 132 UpdateEmail
ECHO. W. 133 UpdatePreferences
ECHO. X. 134 UpdateEmailPreferences
ECHO. Y. 135 UpdateBankDetails
CHOICE /C %CHOICE% /M "CHOOSE AN OPTION"
SET "Option=%ERRORLEVEL%"
rem here scan for correct letter
FOR /L %%a IN (0,1,35) DO if %%a==%Option% set idx=%%a
rem small correction of index
set /A idx-=1
set Option=!Choice:~%idx%,1!
FOR /F "TOKENS=1-4 DELIMS=. " %%A IN ('FINDSTR/BC:"ECHO. " "%~f0"'
) DO (IF "%%B"=="%Option%" (SET "Name=%%C" & SET "Code=%%D" & echo activated %Option%: !Name!,!Code!)
)
,更好地提出选择,然后扫描到正确的字母/数字答案 1 :(得分:0)
我可以建议一种基于arrays的不同方法,它运行得更快,更容易保持更新吗?
@ECHO OFF
MODE CON:COLS=100 LINES=50
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
(SET sourceFolder=C:\Users\Administrator\Desktop\test)
(SET targetFolder=C:\Users\Administrator\Desktop\test2)
SET /P "customerID=Enter Customer ID: "
REM Assemble the data arrays
set i=0
set "options="
FOR /F "TOKENS=1-4 DELIMS=. " %%A IN ('FINDSTR/BC:"ECHO. " "%~f0"') DO (
set /A i+=1
set "options=!options!%%B"
SET "Name[!i!]=%%C"
SET "Code[!i!]=%%D"
)
:MENU
CLS
ECHO=
ECHO= ..................................................
ECHO= PLEASE SELECT THE OPTION FROM THE EVENT MENU BELOW
ECHO= ..................................................
ECHO Option Number Event Number Event Name
ECHO/
ECHO. 0. 101 NewCustomer
ECHO. 1. 102 ExisingCustomer
ECHO. 2. 103 LockedAccount
ECHO. 3. 104 DeleteAccount
ECHO. 4. 105 ExpireSession
ECHO. 5. 106 PasswordUpdated
ECHO. 6. 107 PasswordReset
ECHO. 7 108 HackedAccount
ECHO. 8. 109 UpdateProfile
ECHO. 9. 110 UpdateLists
ECHO. A. 111 NewPurchase
ECHO. B. 112 ExisingSale
ECHO. C. 113 AmendOrder
ECHO. D. 114 AmendDelivery
ECHO. E. 115 CancelOrder
ECHO. F. 116 OvernightFiles
ECHO. G. 117 DailyFiles
ECHO. H. 118 HelpFlies
ECHO. I. 119 FraudAccount
ECHO. J. 120 DeadCustomer
ECHO. K. 121 WelcomeEmail
ECHO. L. 122 OrderEmail
ECHO. M. 123 OrderAmmended
ECHO. N. 124 NoRemainingStock
ECHO. O. 125 ReplenishStock
ECHO. P. 126 SalesQuery
ECHO. Q. 127 UpdateFirstName
ECHO. R. 128 UpdateSurname
ECHO. S. 129 UpdateAddress
ECHO. T. 130 UpdateDateOfBirth
ECHO. U. 131 UpdateContactNo
ECHO. V. 132 UpdateEmail
ECHO. W. 133 UpdatePreferences
ECHO. X. 134 UpdateEmailPreferences
ECHO. Y. 135 UpdateBankDetails
CHOICE /C %options% /M "CHOOSE AN OPTION"
SET "Option=%ERRORLEVEL%"
SET "Name=!Name[%Option%]!" & SET "Code=!Code[%Option%]!"
FOR /F "DELIMS=" %%A IN (
'FINDSTR/MISC:"%customerID%" "%sourceFolder%\*"^|FINDSTR/MIF:/ /C:"%Name%"'
) DO COPY "%%A" "%targetFolder%"
PAUSE
答案 2 :(得分:0)
作为替代方案:
@ECHO OFF
MODE CON:COLS=50 LINES=50
SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION
(SET sourceFolder=C:\test)
(SET targetFolder=C:\test2)
SET /P "customerID=Enter Customer ID: "
:MENU
"SET _="
CLS
ECHO=
ECHO= ................................................
ECHO= PLEASE SELECT THE EVENT CODE FROM THE MENU BELOW
ECHO= ................................................
ECHO=
ECHO= Event Code -=- Event Name
ECHO=
ECHO. 101 --- NewCustomer
ECHO. 102 --- ExisingCustomer
ECHO. 103 --- LockedAccount
ECHO. 104 --- DeleteAccount
ECHO. 105 --- ExpireSession
ECHO. 106 --- PasswordUpdated
ECHO. 107 --- PasswordReset
ECHO. 108 --- HackedAccount
ECHO. 109 --- UpdateProfile
ECHO. 110 --- UpdateLists
ECHO. 111 --- NewPurchase
ECHO. 112 --- ExisingSale
ECHO. 113 --- AmendOrder
ECHO. 114 --- AmendDelivery
ECHO. 115 --- CancelOrder
ECHO. 116 --- OvernightFiles
ECHO. 117 --- DailyFiles
ECHO. 118 --- HelpFlies
ECHO. 119 --- FraudAccount
ECHO. 120 --- DeadCustomer
ECHO. 121 --- WelcomeEmail
ECHO. 122 --- OrderEmail
ECHO. 123 --- OrderAmmended
ECHO. 124 --- NoRemainingStock
ECHO. 125 --- ReplenishStock
ECHO. 126 --- SalesQuery
ECHO. 127 --- UpdateFirstName
ECHO. 128 --- UpdateSurname
ECHO. 129 --- UpdateAddress
ECHO. 130 --- UpdateDateOfBirth
ECHO. 131 --- UpdateContactNo
ECHO. 132 --- UpdateEmail
ECHO. 133 --- UpdatePreferences
ECHO. 134 --- UpdateEmailPreferences
ECHO. 135 --- UpdateBankDetails
ECHO=
SET/P "PICK= > "
FOR /F "EOL=F TOKENS=2-3 DELIMS=.- " %%A IN ('FIND " --- " "%~f0"') DO (
IF %PICK%==%%A (SET "_=T"
FOR /F "DELIMS=" %%C IN (
'FINDSTR/MISC:"%customerID%" "%sourceFolder%\*"
^|FINDSTR/MIF:/ /C:"%%B"') DO COPY "%%C" "%targetFolder%"))
IF NOT DEFINED _ GOTO :MENU
TIMEOUT -1