为用户提供在批处理文件中导航文件系统的选项

时间:2015-08-13 15:16:00

标签: batch-file svn

我需要帮助知道如何使用批处理文件浏览文件系统。

目前我的代码看起来像这样:

echo ============================================================  
echo This batch file will automate opening a workspace in eclipse 
echo ============================================================  %NL%


set svnbin="C:\Program Files\VisualSVN Server\bin\svn.exe"
set svnroot= some_svn_link 

%svnbin% list %svnroot%> projects.txt

type projects.txt

echo ============================================================%NL%  
set /p checkout="Enter project name to checkout="

set svnfolder= %svnroot% / %checkout% /trunk/ 
set CheckOutLocation=C:\Users\user_name\workspace\

在运行批处理文件时,用户会看到文件列表,因为它是在projects.txt中复制的,我在标准输出上键入它。 如何通过让用户选择通过目录导航来替换保存此txt文件并使其更具功能性?

由于

1 个答案:

答案 0 :(得分:0)

此菜单选择器由Aacini编写,可用于选择文件。

我修改了下面的部分,以便在当前目录中查找.txt文件,它应该能够很好地完成你需要的工作。

rem Define the options
set numOpts=0
for %%a in (*.txt) do (
   set /A numOpts+=1
   set "option[!numOpts!]=%%a"
)

这是原始代码

@if (@CodeSection == @Batch) @then


@echo off
setlocal EnableDelayedExpansion

rem Multi-line menu with options selection via DOSKEY
rem Antonio Perez Ayala


rem The creation of a multi-line menu that allows to select options via arrow keys has been an old request in Batch files. This type of selection menu may be developed with the aid of auxiliary programs, like GetKey to get the selection keys and a combination of CursorPos/ColorShow to deselect the current option and highlight the new one; however, such a program is somewhat complex.
rem 
rem I devised a simpler method to achieve such selection menu using DOSKEY program. This DOS command store the lines executed in the command-line (like inputs to SET /P command) and store they in a history that may be displayed in the form of a selection menu when F7 key is pressed. This way, the method consist in:
rem 
rem     Clear previous DOSKEY history.
rem     Execute several SET /P commands that read the menu options, so the DOSKEY history is filled with them.
rem     Send a F7 key to the keyboard.
rem     Execute a SET /P "OPTION=Prompt: "; the input to this command will be completed via the selection menu of DOSKEY.
rem
rem There is a strange point about this program: the DOSKEY /REINSTALL command clear the history only when it is executed the first time. If previous program is executed a second time in the same cmd.exe session, the DOSKEY history is not cleared, so menu options are wrong. I read DOSKEY documentation in Microsoft and SS64 sites and didn't found any reference about this problem. I tested this program in Windows 8, so I don't know if this problem also appear in other versions...
rem 
rem Antonio



rem Define the options
set numOpts=0
for %%a in (First Second Third Fourth Fifth) do (
   set /A numOpts+=1
   set "option[!numOpts!]=%%a Option"
)
set /A numOpts+=1
set "option[!numOpts!]=exit"

rem Clear previous doskey history
doskey /REINSTALL
rem Fill doskey history with menu options
cscript //nologo /E:JScript "%~F0" EnterOpts
for /L %%i in (1,1,%numOpts%) do set /P "var="

:nextOpt
cls
echo MULTI-LINE MENU WITH OPTIONS SELECTION
echo/
rem Send a F7 key to open the selection menu
cscript //nologo /E:JScript "%~F0"
set /P "var=Select the desired option: "
echo/
if "%var%" equ "exit" goto :EOF
echo Option selected: "%var%"
pause
goto nextOpt


@end

var wshShell = WScript.CreateObject("WScript.Shell"),
    envVar = wshShell.Environment("Process"),
    numOpts = parseInt(envVar("numOpts"));

if ( WScript.Arguments.Length ) {
   // Enter menu options
   for ( var i=1; i <= numOpts; i++ ) {
      wshShell.SendKeys(envVar("option["+i+"]")+"{ENTER}");
   }
} else {
   // Enter a F7 to open the menu
   wshShell.SendKeys("{F7}");
}