how to rename files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: how to rename files

#16 Post by doscode » 18 Feb 2012 10:24

Yes. My assumption in the code is that both <title> and </title> are on the same line but even that could be false.[/quote]

It is on same line. I see no reason why somebody wouldn't do so.

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: how to rename files

#17 Post by !k » 18 Feb 2012 10:39

doscode wrote:I have files *.html like "Collection-396.html". Every file contains description which is like "<title>Aasiaat (BGAA)</title>". Is any way how to get the title, for example "Aasiaat (BGAA)" and to rename the html filenames to their titles? So the resulting file would be like Aasiaat (BGAA).html

?Do you have "Total Commander" _http://www.ghisler.com/ — Use his multirename tool with _http://www.totalcmd.net/plugring/wdx-seo-html.html plugin.

Or, if you sharply like batch — "WDX columns extractor" _http://forum.wincmd.ru/viewtopic.php?p=87314#87314 (last link on page) with those plugin

doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: how to rename files

#18 Post by doscode » 18 Feb 2012 15:22

Foxidrive, I have tested your code and I think it is interesting idea to make new file to it. Maybe it would be not necessary so I will try yet simplify for new the version. This is just how the files will be renamed.

ren "Collection-407.html" "Thule (BGTL)(MIL).html"
ren "Collection-408.html" "Upernavik (BGUK).html"
ren "Collection-405.html" "Qaanaaq (BGQQ).html"
ren "Collection-406.html" "Sisimiut (BGSS).html"
ren "Collection-403.html" "Nuuk (BGGH).html"
ren "Collection-404.html" "Paamiut (BGPT).html"
ren "Collection-409.html" "Uummannaq-Qaarsut (BGUQ).html"
ren "Collection-399.html" "Kulusuk (BGKK).html"
ren "Collection-398.html" "Kangerlussuaq (BGSF).html"
ren "Collection-397.html" "Ilulissat (BGJN).html"
ren "Collection-393.html" "AD 2 AERODROMES.html"
ren "Collection-396.html" "Aasiaat (BGAA).html"
ren "Collection-94.html" "Aeronautical Information Packages (AIS).html"
ren "Collection-91.html" "_English.html"
ren "Collection-402.html" "Nerlerit Inaat (BGCO).html"
ren "Collection-400.html" "Maniitsoq (BGMQ).html"
ren "Collection-401.html" "Narsarsuaq (BGBW).html"
ren "Collection-391.html" "AIP PART 3 - AERODROMES (AD).html"
ren "Collection-108.html" "AIP Greenland.html"
ren "Collection-12.html" "Luftfartsinformation (AIS).html"
ren "Collection-30.html" "AIP Grønland.html"
ren "Collection-390.html" "AIP PART 3 - FLYVEPLADSER (AD).html"

And thanks for your inventions.

Aacini
Expert
Posts: 1934
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: how to rename files

#19 Post by Aacini » 21 Feb 2012 16:00

Code: Select all

@echo off
setlocal EnableDelayedExpansion
for %%a in (*.html) do (
   for /F "delims=" %%b in ('findstr /C:"<title>" "%%a"') do (
      set "line=%%b"
      set "line=!line:<title>=$!"
      set "line=!line:</title>=$!"
      for /F "tokens=2 delims=$" %%c in ("!line!") do set "title=%%c"
   )
   ren "%%a" "!title!.html"
)

If the $ character may appear in the line containing the Title, it must be change by another unused character.

Post Reply