0

好的,所以从标题中您可能对我想要完成的事情有所了解。

我想要做的是[树]并显示文件夹列表(因此是树命令),然后允许我使用数字选择一个文件夹,问题是我需要能够在不知道文件夹的情况下这样做名字的

前任。[这就是我不希望它做的]

cd C:\windows
tree
set input=
set /p input=Choose:
if %input%== Folder 1 goto :B
if %input%== Folder 2 goto :C
etc.

所以我需要它能够树,将每个文件夹设置为变量,然后允许我选择它作为一个数字如何?

请帮忙!

4

2 回答 2

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 : "");
于 2013-05-14T04:34:37.773 回答
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
于 2013-05-15T03:54:48.500 回答