سؤال

ok so from the title you might have an idea as to what im trying to accomplish.

What I want to do is [ tree ] and show a list of folders ( hence the tree command ) and then allow me to select a folder by using numbers, the catch is that I need to be able to do so without already knowing the folder's name's

Ex. [ THIS IS WHAT I DONT WANT IT TO DO ]

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

So i need it to be able to tree, set each folder as a variable and then allow me to choose that as a number some how?

Please help!

هل كانت مفيدة؟

المحلول

Try this Batch file, I think it is an adequate solution for this problem:

@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

نصائح أخرى

Run this batch file - it allows you to pick a folder and then returns the folder path in a variable.

@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 : "");
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top