好的,从标题中你可能知道我想要完成什么。
我想要做的是[树]并显示一个文件夹列表(因此树命令),然后允许我使用数字选择一个文件夹,捕获的是我需要能够这样做而没有知道文件夹的名称
实施例。 [这就是我不想做的事情]
cd C:\windows
tree
set input=
set /p input=Choose:
if %input%== Folder 1 goto :B
if %input%== Folder 2 goto :C
etc.
所以我需要它能够树,将每个文件夹设置为一个变量然后允许我选择一个数字一些如何?
请帮忙!
答案 0 :(得分:2)
运行此批处理文件 - 它允许您选择一个文件夹,然后在变量中返回文件夹路径。
@if (@CodeSection == @Batch) @then
@echo off
echo Select a folder:
pause
for /F "delims=" %%a in ('CScript //nologo //E:JScript "%~F0"') do (
set Destination_Folder=%%a
)
echo "%Destination_Folder%"
pause>nul
:EXIT
exit
@end
// Creates a dialog box that enables the user to select a folder and display it.
var title = "Select a folder", rootFolder = 0;
var shl = new ActiveXObject("Shell.Application");
var folder = shl.BrowseForFolder(0, title, 0, rootFolder);
WScript.Stdout.WriteLine(folder ? folder.self.path : "");
答案 1 :(得分:2)
试试这个批处理文件,我认为这是解决这个问题的适当方法:
@echo off
echo Select a folder. Terminate folder number with + to open it.
echo/
call :SelectFolder selectedFolder
echo/
echo Selected folder: %selectedFolder%
goto :EOF
:SelectFolder returnVar
setlocal EnableDelayedExpansion
:nextFolder
echo/
echo %cd%
set i=0
set folder[0]=..
echo 0- ..
for /D %%d in (*) do (
set /A i+=1
set folder[!i!]=%%d
echo !i!- %%d
)
:getOption
set option=0+
set openFolder=1
set /P "option=Enter the desired folder: "
if "%option:~-1%" equ "+" (
set option=%option:~0,-1%
) else (
set openFolder=
)
if %option% gtr %i% goto getOption
cd "!folder[%option%]!"
if defined openFolder goto nextFolder
endlocal & set %1=%cd%
exit /B