Search code examples
filebatch-filecmdsendto

Select multiple files, "send to" batch.cmd, let batch.cmd run a program on selected files


I am using a converter on many files. Usually I just do it one by one but that takes time. I want to be able to select multiple files with CTRL+Lclick, right click, send to a batch.cmd that then runs this code:

"cmd /c dewssdos -P @file"

@file being one file from the "send to" list.

But I have no idea how to do it. I don't know how windows stores the list of files I just sent and how to access that list.

http://technet.microsoft.com/en-us/library/bb490909.aspx

This seems to be somehow related but I am a code noob and have no idea what to do here.

Can you guys help me out?

Thanks a ton!


Solution

  • if you put several files with "send to" to a batch file, this batch file will receive a list of the file names. You can separate them quite easy:

    for %%i in (%*) do echo %%i
    

    %* stands for "all parameters"

    Edit to your comments:

    the variable %%i is only valid within a forcontext. This context ends with a NewLine. You have two possibilities to get around this:

    a) set a variable (works only for first (or only) variable):

    for %%i in (%*) do set var=%%i
    REM %%i is not valid anymore here
    echo %var%
    D:\Spiele\Steam\SteamApps\common\Arma 3 Tools\Audio\WAVToWSS.exe" %var%
    DEL %var%
    

    b) extend the forcontext:

    for %%i in (%*) do (
        echo %%i
        if /i "%%~xi" == ".wav" D:\Spiele\Steam\SteamApps\common\Arma 3 Tools\Audio\WAVToWSS.exe" %var% && del %%i
        if /i "%%~xi" == ".wss" D:\Spiele\Steam\SteamApps\common\Arma 3 Tools\Audio\WAVToWSS.exe" %var% && del %%i
    )
    REM %%i is not valid anymore here
    

    && works as "if previous command was successful then". So the files should only be deleted, if the conversion was successful.