Solved Problem with characters in file name and path

April 26, 2013 at 08:23:57
Specs: Windows 7, amd 5200 / 2 gigs
Hello:

First, excuse me for my English: I'm from spain.

I've got this line on a batch file:

for /f %%i in ('"mediainfo.exe --Inform=Video;%%FrameRate%% %1"') do set vrate=%%i

%1 is the full path and file name of the file I open with this batch file (I drag and drop the file (a movie) over the batch file) , and the problem is that if the name or the path of the file has a , or a space, then the batch file doesn't work. I tried to use "%1" but it didn't work.

Thanks!!


See More: Problem with characters in file name and path

Report •


✔ Best Answer
April 28, 2013 at 01:06:16
Well, I made it work!!

I did this to solve the problem with the path:

set var1=%~f1
Mediainfo.exe --Inform=Video;%%FrameRate%% "%var1%"

This way I could get the info I needed (23'98, 24, 25, 30...). The problem now was how to use that info to set a new variable (vrate) to be used in the next if statement:

if %vrate% leq 24.000 dc -width=1920 -height=1080 -refresh=24 -quiet & goto startvideo

Then I found that Mediainfo has an option to create a log file, so I sent the info I needed to that file (hz.txt) and I set the "vrate" variable. Finally, this is what I got:

PATH E:\Programas\AutoResChanger;E:\Programas\AutoResChanger\MediaInfo;E:\Programas\AutoResChanger\Display Changer;E:\Programas\AutoResChanger\MPC-HC

set var1=%~f1
Mediainfo.exe --Inform=Video;%%FrameRate%% --LogFile=E:\Programas\AutoResChanger\MediaInfo\HZ.txt "%var1%"
FOR /F %%i IN (E:\Programas\AutoResChanger\MediaInfo\HZ.txt) do set vrate=%%i
if %vrate% leq 24.000 dc -width=1920 -height=1080 -refresh=24 -quiet & goto startvideo

And this way everything seems to work fine!!!

The only question now is If there's a way to do it without using the log file ...

Thank you very much to all of you!!!!



#1
April 26, 2013 at 08:51:26
try this:

for /f %%i in ('mediainfo.exe --Inform=Video;%%FrameRate%% "%1"') do set vrate=%%i

=====================
M2 Golden-Triangle


Report •

#2
April 26, 2013 at 09:45:41
for /F %%i in ('mediainfo.exe --Inform=Video;%%FrameRate%% "%*"') do set vrate=%%i


Report •

#3
April 26, 2013 at 13:43:49
Mechanix2Go:
Thank you very much, but it didn't work.

Ivo:
Thank you too, your line solves the , problem, but not the problem with the spaces in the name (or the path) of the file.


Thank you very much to both of you.


Report •

Related Solutions

#4
April 26, 2013 at 14:51:31
My xp puts the dragged item into quotes, so maybe this combination of the previous codes:

for /F %%i in ('mediainfo.exe --Inform=Video;%%FrameRate%% %*') do set vrate=%%i

in other words, %* without the dbl quotes.


Report •

#5
April 27, 2013 at 01:57:03
Thank you very much, nbrane, but it didn't work.

Report •

#6
April 27, 2013 at 03:45:11
If we get mediainfo.exe maybe we can hash it out.

=====================
M2 Golden-Triangle


Report •

#7
April 27, 2013 at 07:49:36
This script tries to work as a auto-resolution changer depending on the frame-rate of the video i want to play. I use Mediainfo to read that info (23'98, 24, 25, 30...), and then change the resolution with display changer:
______________________________________________________________________
@echo off

PATH E:\Programs\AutoResChanger;E:\Programs\AutoResChanger\MediaInfo;E:\Programs\AutoResChanger\Display Changer;E:\Programs\AutoResChanger\MPC-HC

:Framerate
for /f %%i in ('"mediainfo.exe --Inform=Video;%%FrameRate%% %1"') do set vrate=%%i
if %vrate% leq 24.000 dc -width=1920 -height=1080 -refresh=24 -quiet & goto startvideo:
______________________________________________________________________


Report •

#8
April 27, 2013 at 09:14:03
for /F %%i in ('mediainfo.exe --Inform=Video;%%FrameRate%% %~s1') do set vrate=%%i


Report •

#9
April 27, 2013 at 10:54:02
Wow, batch files are very complicated!

Ivo, thank you very much for your last suggestion, it solves much of the problem! I've realized that using only the ' makes the script doesn't work properly, because the framerate is unknown, so I have used:

for /F %%i in ("mediainfo.exe --Inform=Video;%%FrameRate%% %~s1"') do set vrate=%%i

And Using %~s1 is absolutely perfect when i play files of the same computer! But the problem still present when the files are stored in the other pcs of my network. It seems that the short names doesn't work with network files. Any idea?

Thank you very much!


Report •

#10
April 27, 2013 at 11:44:49
I'm not sure why this hasn't been suggested yet:
for /F %%i in ('mediainfo --Inform=Video;%%FrameRate%% %1') do set vrate=%%i

Also, make sure "mediainfo.exe" is in the PATH.

How To Ask Questions The Smart Way


Report •

#11
April 27, 2013 at 13:08:00
Razor2.3, thank you very much, but it didn't solve the problem.

Report •

#12
April 27, 2013 at 21:16:30
Ha ha! this one's been a (female-dog.) If it's a mediainfo issue, might just copy the file over to something very simple, like "x":
copy %1E:\Programs\AutoResChanger\MediaInfo\x
for /F %%i in ('mediainfo --Inform=Video;%%FrameRate%% x') do set vrate=%%i

(I believe it's a problem with mediainfo's parsing, not the batch delivery.)
the only trick is getting x into the proper path for the mediainfo to use. It's unnecessary overhead (network copy), but whatever works works (or doesn't). As usual, the most headaches come from the path - ie: where does mediainfo default it's working-path to. And as usual, this usually needs tweaked (so "x" might have to be path-qualified). Another option might be to use command-line instead of drag/drop method, but I don't know.


Report •

#13
April 28, 2013 at 01:06:16
✔ Best Answer
Well, I made it work!!

I did this to solve the problem with the path:

set var1=%~f1
Mediainfo.exe --Inform=Video;%%FrameRate%% "%var1%"

This way I could get the info I needed (23'98, 24, 25, 30...). The problem now was how to use that info to set a new variable (vrate) to be used in the next if statement:

if %vrate% leq 24.000 dc -width=1920 -height=1080 -refresh=24 -quiet & goto startvideo

Then I found that Mediainfo has an option to create a log file, so I sent the info I needed to that file (hz.txt) and I set the "vrate" variable. Finally, this is what I got:

PATH E:\Programas\AutoResChanger;E:\Programas\AutoResChanger\MediaInfo;E:\Programas\AutoResChanger\Display Changer;E:\Programas\AutoResChanger\MPC-HC

set var1=%~f1
Mediainfo.exe --Inform=Video;%%FrameRate%% --LogFile=E:\Programas\AutoResChanger\MediaInfo\HZ.txt "%var1%"
FOR /F %%i IN (E:\Programas\AutoResChanger\MediaInfo\HZ.txt) do set vrate=%%i
if %vrate% leq 24.000 dc -width=1920 -height=1080 -refresh=24 -quiet & goto startvideo

And this way everything seems to work fine!!!

The only question now is If there's a way to do it without using the log file ...

Thank you very much to all of you!!!!


Report •


Ask Question