# Can I browse for destination in a Bat file??



## NTeyeball

Hey all,

Long time since I played with Batch files, but things may have improved since 1990.

I already have a bat file that "backs-up" selected files to a fixed destination drive, and wish to know if it is possible, can I select a different location from within the bat file? eg: display a browse window.

I have many puters and drives, presently I have to write a batfile for each application. Just curious!!

I have perused pages of Batch file tutorials and found nothing.

NT.


----------



## Squashman

Batch files do not have GUI interfaces.
You could just create a menu to ask the user which location they want to backup. Or you could physically prompt the person for the path they want to backup. THey could physically type it in or just copy and past it in.

But I do have a third party batch add on that you can check out. If I can find the darn link to it.


----------



## Stu_computer

Hey NT,

Like Squashman has already indicated you can call on gui's from within batches but the batch command set itself is text based.


you can make your own gui's and use them in batch files. here's a few i made with AutoIt if you want to give them a try.
note: AutoIt may trigger a false positive 'appl/aclset application' alarm with some antivirus software.

the following is in my AutoIt_xamples.zip below (Au3 source files included)...

ChooseDir.exe /is a select folder gui that returns path string/

example: i made a one line batch named CDG.bat...


Code:


@FOR /F "tokens=*" %%i IN ('ChooseDir.exe') DO @CD %%i

then put CDG.bat and ChooseDir.exe in my windows folder to easily move around on the hdd by simply typing CDG.
----------------------
BatAnswer.exe /input box to pass a string into batch/
(if can't use SET /P variable=[promptString] or you prefer a dialog box)

example: askme.bat using BatAnswer to get ?filenames.??* (on-the-fly) to copy to destination folder


Code:


@FOR /F "tokens=^" %%A IN ('BatAnswer.exe') DO @FOR /F "tokens=*" %%i IN ('ChooseDir.exe') DO @Copy %%A %%i

---------------------
CopyFiles.exe /is a multi pick file select gui with ChooseDir destination/
-can use shift/ctrl and mouse banding to multi pick files.
-can use Files of Type list to display only specific file types like...
All Files (*.*)
Text (txt doc pdf)
Images (jpg bmp)
Videos (avi mpg)
Audio (mp3 wav)
Txt (*.txt)
-gui also has new folder and file details icons.
----------------------

CopyFiles can be used in command/batch or in windows, the other two are strictly command/batch.


----------



## NTeyeball

Hey,

Thanks guys for that input, will be off to have a play.
I didn't think to look for add-ins.....derrr

Have a good one.
NT.


----------



## Squashman

With some help from TheOutcaste I figured this out calling a Vbscript from a batch file.

GetFolder.bat


Code:


@echo off
For /F "Tokens=1 Delims=" %%I In ('cscript //nologo BrowseFolder.vbs') Do Set _FolderName=%%I
echo %_FolderName%

BrowseFolder.vbs


Code:


Const MY_COMPUTER = &H11&
Const WINDOW_HANDLE = 0
Const OPTIONS = 0

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(MY_COMPUTER)
Set objFolderItem = objFolder.Self
strPath = objFolderItem.Path

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder _
    (WINDOW_HANDLE, "Select a folder:", OPTIONS, strPath)
     
If objFolder Is Nothing Then
    Wscript.Quit
End If

Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path

Wscript.Echo objPath


----------

