0

I am building a simple script that I will be adding ffmpeg to after this part works.

@echo off
setlocal disabledelayedexpansion
for /R %%B in (*.mp4,*.mkv) do (
    mediainfo.exe "--Inform=Video;%%Format%%" "%%B" > temp.txt
    for /f %%G in (temp.txt) do (set tester=%%G)
    echo test: %%G
    echo video: %tester%
)
pause

The echo's have no data. The file temp.txt has the correct info. So the mediainfo command is working, but the for /f loop is not assigning the data to environment variable tester. I cannot use EnableDelayedExpansion because there could be exclamation marks in the file names. I also tried set /p tester=<temp.txt with the same results.

Here is the output in the command window:

test: %G
video:
Press any key to continue . . .

What am I doing wrong?

Mofi
  • 46,139
  • 17
  • 80
  • 143
dcol
  • 11
  • 5
  • Can you explain what `%%Format%%` is supposed to be or do? – Compo Jan 14 '21 at 18:40
  • @Compo, %%Format%% is the option that picks the video format, ie AVC,HEVC, etc – dcol Jan 14 '21 at 22:05
  • Sorry, I was being deliberately cryptic, the main reason I asked was that as there are usually more than one `format` field names, I would have expected you to use `%%Format/String%%`, or `%%Format/String1%%`, instead. However, I was also aware that `%Format%` looked too much like a standard Windows variable, and didn't want others to complain that you were using a variable, you hadn't defined. _(Thanks at least for clarifying)_. – Compo Jan 14 '21 at 22:10
  • Because this is way too complicated, and it shouldn't be, I think a better approach is removing the exclamation mark from the filename before applying the EnableDelayedExpansion since that was the only reason I am not using EnableDelayedExpansion. Now I need to figure out how to do that. – dcol Jan 14 '21 at 22:28

1 Answers1

0

What I did to fix this was use a powershell script before the execution of the batch here is the remove.ps1 file

get-childitem -recurse -Include *.mp4 | foreach { rename-item $_ $_.Name.Replace("!", "") }

here is what I added to the beginning of the bat file Since I am only dealing with media files, I just wanted to remove the exclamation marks anyway. Or you can modify the PS script to substitute a different character. Now the batch script can handle files that have exclamation marks.

@echo off
pushd "G:\convert\files"
powershell -file G:\convert\remove.ps1

dcol
  • 11
  • 5