简体   繁体   中英

Folder chooser dialog from a Windows batch script

How do I implement the following code:

@if (@a==@b) @end /*

:: fchooser2.bat
:: batch portion

    @echo off
    setlocal

    for /f "delims=" %%I in ('cscript /nologo /e:jscript "%~f0"') do (
        echo You chose %%I
    )

    goto :EOF

    :: JScript portion */

    var shl = new ActiveXObject("Shell.Application");
    var folder = shl.BrowseForFolder(0, "Please choose a folder.", 0, 0x00);
    WSH.Echo(folder ? folder.self.path : '');

With the following result:

结果

In this code:

@echo off 
color a

app\arc x -ep1 -i2 -w. -dp.\OUTLAST_REPACK_GZK\Outlast DATA_0.bin -msrep:d
app\arc x -ep1 -i2 -w. -dp.\OUTLAST_REPACK_GZK\Outlast\_CommonRedist DATA_1.bin -msrep:d
app\arc x -ep1 -i2 -w. -dp.\OUTLAST_REPACK_GZK\Outlast\OLGame DATA_2.bin -msrep:d
app\arc x -ep1 -i2 -w. -dp.\OUTLAST_REPACK_GZK\Outlast\Engine DATA_3.bin -msrep:d
app\arc x -ep1 -i2 -w. -dp.\OUTLAST_REPACK_GZK\Outlast\Binaries DATA_4.bin -msrep:d

To select the destination folder to extract a file to in batch.

Like the following or another way, I don't know how to do this:

app\arc x -ep1 -i2 -w. -dp.\%FCHOOSER2%\Outlast DATA_0.bin -msrep:d

This should work - but I am unsure about the -dp switch and syntax with the period. Check the arc.exe documentation.

The pause will allow you to read any error messages.

@if (@a==@b) @end /*

:: fchooser2.bat
:: batch portion

    @echo off
    setlocal

    for /f "delims=" %%I in ('cscript /nologo /e:jscript "%~f0"') do (
        echo You chose "%%I"
        set "folder=%%I"
    )


@echo off 
color a



app\arc x -ep1 -i2 -r -w. -dp"%folder%\Outlast" DATA_0.bin -msrep:d
app\arc x -ep1 -i2 -r -w. -dp"%folder%\Outlast\_CommonRedist" DATA_1.bin -msrep:d
app\arc x -ep1 -i2 -r -w. -dp"%folder%\Outlast\OLGame" DATA_2.bin -msrep:d
app\arc x -ep1 -i2 -r -w. -dp"%folder%\Outlast\Engine" DATA_3.bin -msrep:d
app\arc x -ep1 -i2 -r -w. -dp"%folder%\Outlast\Binaries" DATA_4.bin -msrep:d
pause

    goto :EOF

    :: JScript portion */

    var shl = new ActiveXObject("Shell.Application");
    var folder = shl.BrowseForFolder(0, "Please choose a folder.", 0, 0x00);
    WSH.Echo(folder ? folder.self.path : '');

Assuming you have these two scripts, one that calls the directory selection dialog and another that executes a series of app\\arc commands, in two separate files, you can try modifying just the former in this way:

@if (@a==@b) @end /*

:: fchooser2.bat
:: batch portion

@echo off
setlocal

for /f "delims=" %%I in ('cscript /nologo /e:jscript "%~f0"') do (
    
)



goto :EOF

:: JScript portion */

var shl = new ActiveXObject("Shell.Application");
var folder = shl.BrowseForFolder(0, "Please choose a folder.", 0, 0x00);
WSH.Echo(folder ? folder.self.path : '');

As you can see, the path returned by the dialog is used in the cd /d command to change to the directory that is the parent of the one selected in the dialog box. (It changes to the parent because it is assumed that the selected directory is the OUTLAST_REPACK_GZK that is referenced in the subsequent app\\arc commands.)

The script then proceeds to call myarchive.bat , which is assumed to be the name of the other batch file, the one that runs the app\\arc commands. (You will probably need to change this name to the real one.)

Thank you so much for your answer foxidrive . I used it to implement the following:

@if (@a==@b) @end /*

:: fchooser2.bat
:: batch portion

@echo off
setlocal

for /f "delims=" %%I in ('cscript /nologo /e:jscript "%~f0"') do (
    set FLDR=%%I
)
app\arc x -ep1 -i2 -r -w. -dp"%FLDR%\outlast" DATA_0.bin -msrep:d
goto :EOF

:: JScript portion */

var shl = new ActiveXObject("Shell.Application");
var folder = shl.BrowseForFolder(0, "Elija la carpeta de instalacion.", 0, 0x00);
WSH.Echo(folder ? folder.self.path : '');

The -r option was the key in the following line, it means recursive.

app\arc x -ep1 -i2 -r -w. -dp"%FLDR%\outlast" DATA_0.bin -msrep:d

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM