Help with a batch file
Moderator: DosItHelp
Help with a batch file
Hello all, you have helped me in the past and more help would be greatly appreciated yet again
I have my movie collection on a NAS that I use with Kodi. Each movie is in a seperate folder and it contains an .nfo file named like the movie.
I would like the final result to be:
<rating>0</rating>
<votes>0</votes>
But right now it's something like this (as an example):
<rating>7.400000</rating>
<votes>12</votes>
The problem is, they obviously all have different ratings and votes, currently.
I have over 1500 movies so I really don't see myself editing each .nfo one by one
Let me know if I didn't provide enough info...
Thanks in advance!
I have my movie collection on a NAS that I use with Kodi. Each movie is in a seperate folder and it contains an .nfo file named like the movie.
I would like the final result to be:
<rating>0</rating>
<votes>0</votes>
But right now it's something like this (as an example):
<rating>7.400000</rating>
<votes>12</votes>
The problem is, they obviously all have different ratings and votes, currently.
I have over 1500 movies so I really don't see myself editing each .nfo one by one
Let me know if I didn't provide enough info...
Thanks in advance!
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Help with a batch file
The easiest thing to do would just be recreate the .nfo files from scratch.
And just save this in the directory where all your movie folders are.
Code: Select all
@echo off
for /f "delims=" %%A in ('dir /s /b *.nfo') do (
(
echo ^<rating^>0^</rating^>
echo ^<votes^>0^</votes^>
)>%%A
)
And just save this in the directory where all your movie folders are.
Re: Help with a batch file
ShadowThief, the problem is rating and votes are not the only infos in the nfo.
Here's an example:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<movie>
<title>Die Hard</title>
<originaltitle>Die Hard</originaltitle>
<sorttitle>Die Hard 1</sorttitle>
<rating>8.400000</rating>
<epbookmark>0.000000</epbookmark>
<year>1988</year>
<top250>0</top250>
<votes>77</votes>
<outline></outline>
<plot>NYPD cop John McClane's plan to reconcile with his estranged wife, Holly, is thrown for a serious loop when minutes after he arrives at her office, the entire building is overtaken by a group of pitiless terrorists. With little help from the LAPD, wisecracking McClane sets out to single-handedly rescue the hostages and bring the bad guys down.</plot>
<tagline>Twelve terrorists. One cop. The odds are against John McClane... That's just the way he likes it.</tagline>
<runtime>132</runtime>
<mpaa>Rated R</mpaa>
<playcount>1</playcount>
<lastplayed>2012-08-24</lastplayed>
<id>tt0095016</id>
<genre>Action</genre>
<genre>Thriller</genre>
<genre>HD</genre>
<country>United States of America</country>
So I really need only the lines rating and votes to be modified and the rest to be left intact.
Here's an example:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<movie>
<title>Die Hard</title>
<originaltitle>Die Hard</originaltitle>
<sorttitle>Die Hard 1</sorttitle>
<rating>8.400000</rating>
<epbookmark>0.000000</epbookmark>
<year>1988</year>
<top250>0</top250>
<votes>77</votes>
<outline></outline>
<plot>NYPD cop John McClane's plan to reconcile with his estranged wife, Holly, is thrown for a serious loop when minutes after he arrives at her office, the entire building is overtaken by a group of pitiless terrorists. With little help from the LAPD, wisecracking McClane sets out to single-handedly rescue the hostages and bring the bad guys down.</plot>
<tagline>Twelve terrorists. One cop. The odds are against John McClane... That's just the way he likes it.</tagline>
<runtime>132</runtime>
<mpaa>Rated R</mpaa>
<playcount>1</playcount>
<lastplayed>2012-08-24</lastplayed>
<id>tt0095016</id>
<genre>Action</genre>
<genre>Thriller</genre>
<genre>HD</genre>
<country>United States of America</country>
So I really need only the lines rating and votes to be modified and the rest to be left intact.
Re: Help with a batch file
This uses a native Windows batch script called Jrepl.bat written by dbenham, which uses jscript to make it robust and swift.
viewtopic.php?f=3&t=6044
Place Jrepl.bat in the same folder as the batch file, or in a folder that is on the system path.
viewtopic.php?f=3&t=6044
Place Jrepl.bat in the same folder as the batch file, or in a folder that is on the system path.
Code: Select all
@echo off
for /f "delims=" %%A in ('dir /s /b *.nfo') do (
call jrepl "<rating>.*</rating>" "<rating>0</rating>" /f "%%A" /o -
call jrepl "<votes>.*</votes>" "<votes>0</votes>" /f "%%A" /o -
)
pause
Re: Help with a batch file
Wow, you guys are something else...
foxidrive, it worked.
Thank you both very much for your time and help!
foxidrive, it worked.
Thank you both very much for your time and help!
Re: Help with a batch file
I would like to complete the information you have about the possible solutions for this problem.
In this site there is another program similar to Jrepl.bat that allows to replace strings inside text files; it is called FindRepl.bat and you may download it from this link. These programs are extensive applications with advanced capabilities that can perform this replacement and many more, much more complex ones.
However, the use of anyone of these programs to perform a task as simple as just replace a couple strings from several small files is certainly a waste of resources that may be achieved in much simpler ways. You don't need hundreds of lines of code to do the same thing, just a small Batch-JScript hybrid script specifically written to solve this problem that would be as robust and fast as anyone of Jrepl.bat or FindRepl.bat.
As a matter of fact, the code below should run faster than the proposed Jrepl.bat solution because the program is much smaller and each data file is processed just one time, that is, the two replacements are completed in the same processing pass instead of process each file one time for each replacement.
As an added bonus, this code is simple enough so you are encouraged to review it, modify it and use it for "what if" testing purposes, something that certainly you can't do with Jrepl.bat or FindRepl.bat original code!
Antonio
In this site there is another program similar to Jrepl.bat that allows to replace strings inside text files; it is called FindRepl.bat and you may download it from this link. These programs are extensive applications with advanced capabilities that can perform this replacement and many more, much more complex ones.
However, the use of anyone of these programs to perform a task as simple as just replace a couple strings from several small files is certainly a waste of resources that may be achieved in much simpler ways. You don't need hundreds of lines of code to do the same thing, just a small Batch-JScript hybrid script specifically written to solve this problem that would be as robust and fast as anyone of Jrepl.bat or FindRepl.bat.
As a matter of fact, the code below should run faster than the proposed Jrepl.bat solution because the program is much smaller and each data file is processed just one time, that is, the two replacements are completed in the same processing pass instead of process each file one time for each replacement.
Code: Select all
@if (@CodeSection == @Batch) @then
@echo off
for /F "delims=" %%a in ('dir /S /B *.nfo') do (
cscript //nologo //E:JScript "%~F0" < "%%a" > "%%a.new"
move /Y "%%a.new" "%%a"
)
goto :EOF
@end
WScript.Stdout.Write(WScript.Stdin.ReadAll().replace(/<rating>.*<\/rating>|<votes>.*<\/votes>/g,
function (A){return {rating:"<rating>0</rating>", votes:"<votes>0</votes>"}[A.slice(1,A.indexOf(">"))]}));
As an added bonus, this code is simple enough so you are encouraged to review it, modify it and use it for "what if" testing purposes, something that certainly you can't do with Jrepl.bat or FindRepl.bat original code!
Antonio
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Help with a batch file
ArieS wrote:ShadowThief, the problem is rating and votes are not the only infos in the nfo.
ArieS wrote:I would like the final result to be:
<rating>0</rating>
<votes>0</votes>
I just gave you what you asked for.
Re: Help with a batch file
ArieS wrote:ShadowThief, the problem is rating and votes are not the only infos in the nfo.
You did not feel that information was pertinent when you posted your question?
Re: Help with a batch file
ShadowThief wrote:ArieS wrote:I would like the final result to be:
<rating>0</rating>
<votes>0</votes>
I just gave you what you asked for.
hehe I was going to rant about that again - people ask for a solution for something they aren't doing. Inaccurate descriptions.
It's crazy!