Need to set variables based on filename

Microsoft Windows xp professional w/serv...
March 23, 2010 at 22:40:58
Specs: Windows XP/Vista/7
Hi,

I am trying to automate the encoding and tagging parts of ripping my DVD TV Series collections for an AppleTV.

Currently I am at a roadblock in this Batch/Command file automation process and could really use some expertise.

Situation: Files end up here:
%temp%\AtomicParsley\
aka C:\Documents and Settings\Administrator\Local
Settings\Temp\AtomicParsley\

The file format is always as follows:
Star Trek - S01E07.m4v
aka Show Name[space]-[space]SnnEnn.m4v

I will be processing a lot of files, but they all follow that exact same format. The Show Name is variable length depending on the name of the show, but it is always followed by a space-space then S (Season) and two
numbers, and E (Episode) and two numbers, and the file extension is always going to be .m4v

What I need: I am wanting to put code into my batch file that will look at the one and only M4V file in that directory and from it set the following variables:

(These example values are based on the Star Trek file
example above)
filename=Star Trek - S01E01.m4v
pathfilename=C:\Documents and Settings\Administrator\Local Settings\Temp\Star Trek - S01E01.m4v
TVShow=Star Trek
Season=01
Episode=07

Thank you so much for help, this will save me a lot of manual intervention as I process all the DVDs for digital storage.


See More: Need to set variables based on filename

Report •


#1
March 24, 2010 at 01:05:10
@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b *.m4v') do (
set pathfilename=%%~DPa
set filename=%%~NXa
for /f "tokens=1-2 delims=-" %%i in ("%%a") do (
set TVShow=%%i
set S=%%~Nj
set Season=!S:~2,2!
set Episode=!S:~5,2!
)
)

echo filename !filename!
echo pathfilename !pathfilename!
echo TVShow !TVShow!
echo Season !Season!
echo Episode !Episode!


=====================================
Helping others achieve escape felicity

M2


Report •

#2
March 24, 2010 at 10:53:32
M2,

Wow, fantastic - I couldn't have done that myself.

One very small thing, the show name ends with a space, e.g.: "Star
Trek ". Is it possible to modify it slightly so that it removes that last
space, so it would be: "Star Trek"?

Thanks!

One additional Request.

It would also be helpful if I could set another variable "nocapspace"
such that "Star Trek" would be "star_trek". So all lower case, and
spaces converted to underscore.

Thanks so much - Karma will be good to you!


Report •

#3
March 24, 2010 at 11:22:33
This should take care of the trailing space. I need to think about the lowercase for a while.

-----------------------------------
@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b *.m4v') do (
set pathfilename=%%~DPa
set filename=%%~NXa
for /f "tokens=1-2 delims=-" %%i in ("%%a") do (
set TVShow=%%i
set TVShow=!TVShow:~0,-1!
set S=%%~Nj
set Season=!S:~2,2!
set Episode=!S:~5,2!
)
)

echo filename !filename!
echo pathfilename !pathfilename!
echo TVShow !TVShow!
echo Season !Season!
echo Episode !Episode!


=====================================
Helping others achieve escape felicity

M2


Report •
Related Solutions


Ask Question