I'm trying to write a command procedure that will pick up the height of a video file and put that into the file name. I've done a number of similar command procedures before, but this one is giving me a problem I've never seen before and which does not appear to be addressed in existing similar questions.
The basic command procedure seem reasonably simple.
@echo onREM setlocalREM setlocal enabledelayedexpansionREM setlocal DISABLEDELAYEDEXPANSIONFOR /F "tokens=*" %%G IN ('dir /b v*.mpg') DO ( mediainfo.exe --Inform=Video;%%Height%% "%%G" > temporary.txt type temporary.txt set /p HeightVar=< temporary.txt echo %HeightVar% REM RENAME "%%~nG" "%%~nG-%HeightVar%p%%~xG")REM endlocalREM setlocal DISABLEDELAYEDEXPANSION
I'm testing this with a set of three files. The first one has a height of 684, the others are 720. The command that runs mediainfo and puts the height value into a temporary file works. I can look at the value and it changes for each file. The rest of the commands seem to be o.k. However, when I run the procedure I see this:
E:\Capture>set "HeightVar="E:\Capture>set hHOMEDRIVE=C:HOMEPATH=\Users\user001E:\Capture>mediainfo.batE:\Capture>REM setlocalE:\Capture>REM setlocal enabledelayedexpansionE:\Capture>REM setlocal DISABLEDELAYEDEXPANSIONE:\Capture>FOR /F "tokens=*" %G IN ('dir /b v*.mpg') DO (mediainfo.exe --Inform=Video;%Height% "%G" 1>temporary.txt type temporary.txt set /p HeightVar= 0<temporary.txt echo 720 REM RENAME "%~nG" "%~nG-720p%~xG")E:\Capture>(mediainfo.exe --Inform=Video;%Height% "Variety_2024-02-08_1601_Pass1.mpg" 1>temporary.txt type temporary.txt set /p HeightVar= 0<temporary.txt echo 720 REM RENAME "Variety_2024-02-08_1601_Pass1" "Variety_2024-02-08_1601_Pass1-720p.mpg")684720E:\Capture>(mediainfo.exe --Inform=Video;%Height% "Variety_2024-02-09_0000_Pass1.mpg" 1>temporary.txt type temporary.txt set /p HeightVar= 0<temporary.txt echo 720 REM RENAME "Variety_2024-02-09_0000_Pass1" "Variety_2024-02-09_0000_Pass1-720p.mpg")720720E:\Capture>(mediainfo.exe --Inform=Video;%Height% "Variety_2024-02-09_1215_Pass1.mpg" 1>temporary.txt type temporary.txt set /p HeightVar= 0<temporary.txt echo 720 REM RENAME "Variety_2024-02-09_1215_Pass1" "Variety_2024-02-09_1215_Pass1-720p.mpg")720720E:\Capture>REM endlocal
I do not understand why the first "set /p HeightVar=< temporary.txt" picks up the wrong value. You can see that temporary.txt contains the correct value, but when the procedure has been run the set command always uses the wrong value.
I have tried every combination of setlocal and endlocal I can think of (inside the loop and outside the loop"; I've tried turning delayed expansion on and off; I've tried every combination of both variables I can think of; I have cleared the value of HeightVar at the command prompt before running the procedure, as you can see from the output I have included here; and I can't get the loop to set the correct value for all of the files being read in the loop.
I'm willing to assume that there is some "simple" error that I'm overlooking, but for the life of me I can't find a combination that will work. I have written a number of other procedures that go through directories finding files and processing the files or information about the files, including using MediaInfo, and this is the only one I've done that isn't working.
This is Windows 7 with all updates, if that matters.
At this point I'm willing to entertain any and all suggestions as to how to fix the problem.