1

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!

Andrej S.
  • 13
  • 1
  • 5

1 Answers1

3

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.

Stephan
  • 53,940
  • 10
  • 58
  • 91
  • Thank you! Jesus christ, this saves me some HEADACHES!!! :D Here is my final code: for %%i in (%*) do cmd /c dewssdos -P %%i Now I am lucky that dewssdos is "registered" with cmd, so I can easily run it. What if I want to run a custom program on these files? For example path to program is: P:\Audio\WavToWss.exe and I want to use the parameter "-stereo". How do I do that? Thank you a TON so far, this is helping tremendously! – Andrej S. Dec 04 '14 at 18:11
  • for %%i in (%*) do p:\Audio\WavToWss.exe %%i Works fine, adding a parameter after it should work fine too, right? Seems to... If I run into any problems, I will come back for help! Thank you so much! :) – Andrej S. Dec 04 '14 at 18:21
  • Hello, is there a way to DELETE a file after it has been run through a program? I tried: for %%i in (%*) do "D:\Spiele\Steam\SteamApps\common\Arma 3 Tools\Audio\WAVToWSS.exe" %%i DEL %%i PAUSE but it tells me "%i could not be found". I must be missing something here. I thought %%i means "file from that list". Why is it looking for "%i"? – Andrej S. Dec 04 '14 at 18:52
  • I will take the 2nd veriant because the first one stops at the first loop. Thank you so so so very much! You have made my live so much easier. :) Please, tell me where I can read up on such variables such as "%%i" etc. – Andrej S. Dec 04 '14 at 21:15
  • ups - my failure. About %%i see `for /?`. Also search for "delayed expansion" here when you have trouble with variables inside a `for`context. – Stephan Dec 05 '14 at 06:10
  • Ah nice, thank you! :) All of this is working tremendously well!!! My work flow is so fast now, thanks! Is there a way to filter for *.wav and *.wss files in the command? So no other files than WSS and WAV are sent to the batch? Thanks! – Andrej S. Dec 05 '14 at 21:04
  • something like `if "%%~xi" ==".wav" echo %%i`? (see `for /?` for explanation) – Stephan Dec 05 '14 at 22:03
  • Hello Stephan, thank you so very much again for this solution. This works great! I have a problem though - if I select TOO MANY objects, the script fails. The CMD window upens, remains empty for a split second but instantly closes again. This usually occurs with around 80-120 files. It seems to depend on the "size" of the list I send to the script. For example: If I use folder structure: c:\folder\sound.wav - I can "send to" a LOT more files compared to if I use: c:\folder\veryLongFolder\AnotherLongFolder\AndAnotherFolder\sound.wav Can you help? – Andrej S. Mar 18 '15 at 22:14
  • @AndrejS. There is a limit, how many chars in a line can be handled. (not sure what it is. Somewhere a bit over 8000?) The longer the path, the less files. This is a limitation of `cmd.exe` and I know no way to break this limit. But maybe you can shorten the used path with `subst /?` – Stephan Mar 19 '15 at 06:44
  • Thank you very much Stephan, I was afraid this was going to be an issue. The files are already on a rather short path. It's good to know that there is nothing more I can do. You really helped me out maximize the efficiency of this workflow. :) Thanks! I guess now I will have to either write a super advanced script (which I can't) or find someone to do it for me. :-/ Hahaha. But it won't be you, you helped enough. Thanks! :) – Andrej S. Mar 22 '15 at 23:40