0

I have one text file (trimlist.txt) with a variable number of lines, but each line are similar with a variable file path and name and 2 numbers separated by coma:

E:\test\00037_20161001_100956.mov,3.6369666,1.2345666

I need to get 3 different variables from each line: mov, 3.6369666 & 1.2345666 in this example. I can get the 2 last variables like this

set prevfile=

for /F "tokens=1,2,3 delims=," %%F in (E:\trimlist.txt) do (
    if "%%F"=="!prevfile!" (
    if "!counter!"=="" (set counter=1) else (set /a counter+=1)
) else (
    set counter=
    set "prevfile=%%F"
        )
ffmpeg -ss "%%G" -i "%%F" -c copy -t "%%H" "%%~dpnF!counter!-trimmed.mov"

So with the above text file my final commmand will be

ffmpeg -ss 3.6369666 -i "E:\test\00037_20161001_100956.mov" -c copy -t 1.2345666 "E:\test\00037_20161001_100956 01 -trimmed.mov"

I would like the "mov" of E:\test\00037_20161001_100956 01 -trimmed.movto be a variable taken from the textfile.

Any help will be greatly appreciated.

Joet
  • 1
  • 1
  • You *can* do this with `cmd` but it will tend to be ugly and error-prone. At some point, all `cmd` people should opt to investigate powershell. – paxdiablo Apr 02 '17 at 08:09
  • have you checked out this: http://stackoverflow.com/questions/17289969/how-to-split-command-output-in-windows-command-prompt it seams what you want is to split at a `,` – Chris Apr 02 '17 at 08:13

2 Answers2

1

Try adding

echo %%~xF

into your outer loop.

It's not clear what you actually want to do - with an example of the output elements required, perhaps it would be easier to help.

set "prevfile="
set "counter="
for /F "tokens=1,2,3 delims=," %%F in (E:\trimlist.txt) do (
    if "%%F"=="!prevfile!" (
    if not defined counter set /a counter=10000
    set /a counter+=1
) else (
    set "counter="
    set "prevfile=%%F"
        )
if defined counter (ffmpeg -ss "%%G" -i "%%F" -c copy -t "%%H" "%%~dpnF-trimmed%%~xF"
) else (
ffmpeg -ss "%%G" -i "%%F" -c copy -t "%%H" "%%~dpnF !counter:~-2! -trimmed%%~xF"
)

I believe this should suit.

Note: The syntax SET "var=value" (where value may be empty) is used to ensure that any stray trailing spaces are NOT included in the value assigned. set /a can safely be used "quoteless".

set var+=1 will happily assign 1 to var if var is undefined.

Since when counter has been defined, you require a space either side of a leading-zero-filled value in the destination-filename, the easiest way would be to initialise counter to a number >100 ending in '00' when you wish to start counting, then select the last two characters of the string.

Magoo
  • 68,705
  • 7
  • 55
  • 76
  • Thanks for your reply. i edit my 1st post to show what the command should look like. Hope that helps. – Joet Apr 02 '17 at 08:43
0

Finally found how to do

setlocal enableDelayedExpansion
set prevfile=
for /F "tokens=1,2,3 delims=," %%F in (E:\trimlist.txt) do (
    if "%%F"=="!prevfile!" (
        if "!counter!"=="" (set counter=1) else (set /a counter+=1)
    ) else (
        set counter=
        set "prevfile=%%F"
    )
    ffmpeg -ss "%%G" -i "%%F" -c copy -t "%%H" "%%~dpnF!counter!-trimmed%%~xF"
)

i only have to get the extension from the file with %%~xF

Joet
  • 1
  • 1