View Full Version : Modifying For loop variable batch file

10-23-2012, 04:46 AM
Thing I want to do is to filter out specific video file extensions from a text file containing various video file names e.g filename.txt contents are

Now I will parse this file for .mp4 only & utilise 'for parameter' to make several .txt files each containing particular code for a particular file. In other words will create number of files same as number of .mp4 video in filename.txt My code

@echo off
setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in ('type filename.txt ^|findstr ".mp4"') do (
set /a n+=1
echo >myfile!n!.txt
set v!n!=x264 --crf 23 --level 3.1 --tune film --o "%%a" "%%a.mkv"
set v
I have **two** problems:

1. How do I modify %%a to have its .mp4 string removed because when I apply "%%a.mkv" a file will be named *.mp4.mkv and I don't want that and .mp4 can be typed manually like --o "%%a.mp4" "%%a.mkv"
2. Provided that required txt files are already created how do I pass variables v1,v2,v3... to its respective text file I tried with

echo %v!n!% > >myfile!n!.txt
within loop but it didn't work, so plz advice