1

I am creating a batch file to change the raw files to wav files and change the file name with a number stored in buffer and increment them.

D:
cd Sphinx_UE4_Demo\Plugins\sphinx-ue4\voice_data
@echo off
setlocal enabledelayedexpansion
set /p i=<buffer.txt
for %x in (*.raw) do (
..\sox-14-4-2\sox -r 16k -e signed -b 16 -c 1 %x %i%.wav
set /A i+=1
)
endlocal

problem is its not getting incremented, what is the mistake?

So if buffer.txt has 0 then expected output is 0.wav,1.wav,2.wav but only 0.wav is getting generated

chinmay rakshit
  • 220
  • 3
  • 11
  • 2
    The problem is `delayed expansion` is required. Please search SO for `delayed expansion` - there are hundreds of articles about it. – Magoo Feb 17 '17 at 13:30
  • I have applied delayed expansion – chinmay rakshit Feb 17 '17 at 13:33
  • 4
    You have not. To access a variable in delayedexpansion mode, you need to use `!var!` in place of `%var%`. You have a second problem - references to the metavariable `x` need a double `%` in batch - but a single `%` direct from the prompt, so `%x` needs to be `%%x` throughout – Magoo Feb 17 '17 at 13:37
  • thanks its working, I was confused with the prompt mode and the batch file mode. – chinmay rakshit Feb 17 '17 at 13:39
  • common errors - everyone makes them a few times. – Magoo Feb 17 '17 at 13:41
  • 1
    Your problem is not a batch file mode versus cmd prompt mode. The expansion of variables inside a code block are the same. Delayed Expansion needs to be enabled and you need to reference them correctly. – Squashman Feb 17 '17 at 14:16

0 Answers0