0

I found this code online, and it allows me to choose a folder using a GUI. Can someone please explain to me how this works, and how I can get an output from it. I am hoping I can get an output and assign that to a variable.

NOTE: I did NOT make this. I simply found it online at another stack overflow post.

:: fchooser.bat
:: launches a folder chooser and outputs choice to the console
:: http://stackoverflow.com/a/15885133/1683264

@echo off
setlocal

set "psCommand="(new-object -COM 'Shell.Application')^
.BrowseForFolder(0,'Please choose a folder.',0,0).self.path""

for /f "usebackq delims=" %%I in (`powershell %psCommand%`) do set "folder=%%I"

setlocal enabledelayedexpansion
echo You chose !folder!
endlocal

Thanks a lot, ChapelCone56

01F0
  • 1,228
  • 2
  • 19
  • 32

1 Answers1

0
set "psCommand="(new-object -COM 'Shell.Application')^.BrowseForFolder(0,'Please choose a folder.',0,0).self.path""

It is creating a new powershell object for windows to invoke the browse folder dialogue

FOR /F 

Loop command against the results of other command.

usebackq

use the different quoting style

powershell %psCommand%

creates a pipileline that another object can use

set "folder=%%I"

setting folder variable to the choosen folder name

echo You chose !folder!

display the choice

if you want to use the selected folder name, use variable folder whose value can be found as !folder!

thepiyush13
  • 1,321
  • 1
  • 8
  • 9