Jump to content

Simple substitution of variables!


Recommended Posts

A simpler problem. More because I actually had the solution after much trial and error but obviously did something stupid when I walked away from the computer.

for /F "tokens=*" %%a in ('dir /b /s Foreign') do (

D:\Desktop\MediaInfo_CLI_0.7.37_Windows_x64\mediainfo.exe --Inform=Video;%%Width%% "%%a" > 1.txt & for /f "tokens=*" %%j in ('type 1.txt') do ren "%%a" "%%~na [%%jp]%%~xa"

) & del 1.txt

That code works perfectly fine, the mediainfo is just there to scrape data from the video file. For reference sake this script is just to help rename my movie files into their respective resolutions (i.e. 720p, 1080p)

However all I wanted to do was a simple substitution of variables because while the width tends to be standard, the height does not. So I wanted to do something like this

for /F "tokens=*" %%a in ('dir /b /s Foreign') do (

D:\Desktop\MediaInfo_CLI_0.7.37_Windows_x64\mediainfo.exe --Inform=Video;%%Width%% "%%a" > 1.txt & for /f "tokens=*" %%j in ('type 1.txt') do (if %%j==1920 set res=1080p else if %%j==1280 set res=720p) & @echo "%%a" "%%~na [%res%]%%~xa"

) & del 1.txt

However that doesn't work, anyone have any ideas as to why? It seemed rather straightforward to me and I did have a solution but then it disappeared on me, making me feel extra silly

Link to comment
Share on other sites


First things first, you appear to be sending a variable as an input parameter to the executable. This parameter should be a file however your script doesn't specify this, (it will pass both files and directories), which could cause you problems.

As far as the script goes, if you decide to stick with nested for loops you will need to implement delayed expansion otherwise you should change your coding accordingly.

I would also strongly suggest that you forget about placing your code into a single line.

Link to comment
Share on other sites

The first line of code works perfectly, the second line was just my attempt to show you what i'm trying to achieve however i'll expand a bit more though. Resolution for HD movies will 90% of the time start with 1920 OR 1280 followed by the height of 1080 or 720 so:

1920x1080

1280x720

Now the widths, being the 1920/1280 tend to be a constant. However the height isn't, you can get 1050 instead of 1080 or 557 instead of 720. It is just how the stuff gets encoded.

So I can't use the height variable obviously because it is all over the place, I need to use the width. However we all refer to HD material as either 1080p or 720p, all retail blu-rays do as well so for cataloging purposes i'd obviously prefer that number.

I wanted to find the Width and then if the variable (%%j as stated above) was 1920 to change it to say 1080p and it if was 1280 to change it to 720p and then do the rename function.

As for placing the code onto a single line I just wrote it out as I pictured it needing to function in my head is all, most of my scripts don't do that i'll admit. Could be why i'm running into all my troubles.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...