Excuse me, your question is not clear enough. After read your question several times, I assumed that you want a method (that may be a Windows batch .bat file) that:
- Allows the user to input the search string.
- Process several files with .html extension.
- Look in each file for the value between
<td>
and</td>
tags that appear in the next line after the first match of the search string, and use it to rename the file.
The Batch file below do such a process:
@if (@CodeSection == @Batch) @then
@echo off
set /P "search=Enter search string: "
for /F "delims=" %%a in ('dir /B /A-D *.html') do (
for /F "delims=" %%b in ('cscript //nologo //e:jscript "%~F0" "%%a"') do (
if "%%b" neq "NoNameFound" (
ECHO ren "%%a" "%%b"
) else (
echo ERROR: No name found in file "%%a"
)
)
)
goto :EOF
@end
var file = new ActiveXObject("Scripting.FileSystemObject").OpenTextFile(WScript.Arguments.Item(0)),
search = WScript.CreateObject("WScript.Shell").Environment("Process")("search"),
re = new RegExp(search+".+\n.+<td>(.+)<\/td>",""), result;
if (result = re.exec(file.ReadAll())) {
WScript.Stdout.WriteLine(result[1]);
} else {
WScript.Stdout.WriteLine("NoNameFound");
}
file.Close();
This is the output with your example data:
C:\> test
Enter search string: <th style="width: 12em;">Name:</th>
ren "input.html" "[NAME]"
Note that this Batch file just display the ren
command, but it does not execute it! You need to remove the ECHO
part before ren
in order to execute it.
If I missed something, please enter a comment with modifications to my specifications.