Skip to content Skip to sidebar Skip to footer

Renaming Multiple Files Based On Document Text String

I have already seen that there is something out there called the Bulk Rename Utility but the data files I would like to rename are relatively confidential and so, perhaps unreasona

Solution 1:

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.

Solution 2:

Change names using powershell and cmd like a boss just refer the link

http://www.howtogeek.com/111859/how-to-batch-rename-files-in-windows-4-ways-to-rename-multiple-files/

Dont come to conclusion before reading whole page.

Post a Comment for "Renaming Multiple Files Based On Document Text String"