Loading ...
Sorry, an error occurred while loading the content.

[Clip] Automatized renaming depending on an html tag

Expand Messages
  • BONG
    I ll try to explain the tricky problem I want to solve. I have about 300 .html files with information about countries. The name of each country is in the head
    Message 1 of 4 , Jul 10 5:40 AM
    • 0 Attachment
      I'll try to explain the tricky problem I want to solve.
      I have about 300 .html files with information about countries. The name of
      each country is in the head tag of the appropriate document, eg
      <HEAD><title>Aruba</title></HEAD>.
      The problem is that the filenames of all the 300 documents are completely
      undescriptive: aa.html, ac.html, af.html and so on. And here's what I'm
      asking: is there a clip or any other tool/way to make the name of each
      country go from a specified place in a document to the filename? Like this:
      the document with the word "Aruba" in the head tag would be renamed to
      aruba.html

      I know it's hard to imagine a solution to this problem... :-/

      BONG



      ------------------------------------------------------------------------

      eGroups.com home: http://www.egroups.com/group/ntb-clips
      http://www.egroups.com - Simplifying group communications
    • Grant
      ... Doing this sort of thing is bread and butter stuff for Notetab Pro. Try doing this in those $200 plus WYSIYG html editors The following clip requires
      Message 2 of 4 , Jul 10 7:32 PM
      • 0 Attachment
        > I'll try to explain the tricky problem I want to solve.
        > I have about 300 .html files with information about countries. The name of
        > each country is in the head tag of the appropriate document, eg
        > <HEAD><title>Aruba</title></HEAD>.
        > the document with the word "Aruba" in the head tag would be renamed to
        > aruba.html

        Doing this sort of thing is bread and butter stuff for Notetab Pro.
        Try doing this in those $200 plus WYSIYG html editors
        The following clip requires Notetab Pro 4.6.
        It does what you require for all the files in a particular folder.
        Check that the long lines of the following clip are not wrapped by your
        email client.
        Check the %FileSpecs% match what you require.
        Note;The ReNameDoc function does'nt seem to require you to reset doc
        extension.
        *******************

        ^!Set %FilePath%=^?{(T=D)Get Folder=}
        ^!Continue ^%FilePath%
        ^!Set %FileSpecs%="*.htm"
        ^!Set %File%=^$GetFileFirst(^%FilePath%;^%FileSpecs%)$
        ^!StatusShow Opening files in ^%FilePath%.
        :LoopDeLoop
        ^!IfTrue ^$IsEmpty(^%File%)$ ToDoNext
        ^!Open ^%File%
        ;do something with file
        ;get Title content
        ^!Set %Str%=^$GetText$
        ^!Set
        %Str%=^$StrDelete(^%Str%;^$StrPos(</TITLE>;^%Str%;False)$;^$StrSize(^%Str%)$
        )$
        ^!Set %Str%=^$StrDelete(^%Str%;1;^$StrPosRight(>;^%Str%;False)$)$
        ;massage the string
        ;to lowerCase
        ^!Set %Str%=^$StrLower(^%Str%)$
        ;Trim just in case
        ^!Set %Str%=^$StrTrim(^%Str%)$
        ;Replace gaps with Underscore
        ^!Set %Str%=^$StrReplace(" ";"_";^%Str%;True;True)$
        ^!RenameDoc ^%Str%
        ^!Save
        ^!Close
        ^!Set %File%=^$GetFileNext$
        ^!GoTo LoopDeLoop
        :ToDoNext
        ^!StatusClose
        ^!INFO Finished


        ------------------------------------------------------------------------

        eGroups.com home: http://www.egroups.com/group/ntb-clips
        http://www.egroups.com - Simplifying group communications
      • Jody
        Hi Grant and Bong, ... You got that right Grant!!! I was just finishing mine up to make it so anybody could use it. I have peculiars in most my clips for my
        Message 3 of 4 , Jul 10 8:59 PM
        • 0 Attachment
          Hi Grant and Bong,

          >Doing this sort of thing is bread and butter stuff for Notetab Pro.
          >Try doing this in those $200 plus WYSIYG html editors
          >The following clip requires Notetab Pro 4.6.

          You got that right Grant!!!

          I was just finishing mine up to make it so anybody could use it.
          I have peculiars in most my clips for my own purposes. I see we
          did about the same thing. I have some that use
          GetFileFirst/Next, but chose to just open all the docs in this
          one first. I believe it is faster in the long run and also
          allows the user to pick files from different folders. You all
          with those screaming fast machines don't have to be concerned
          with that stuff though.

          I also started to remove the spaces like you in the title name,
          but decided not to in case someone wants the space between two
          words. I suppose it should have the hex ?? equivalent in there
          though. I don't know enough about it. I did get hard line
          breaks and tabs though because I have seen those in title tags.

          To use this version open all the files you want renamed and click
          on the clip. I added some extra clips that I like using when
          dealing with a lot of files open as well.

          The clip will select everything between the two tags and strip
          line breaks, tabs, and spaces from each side of it once the
          selection is put into a variable. It will not edit the document.
          I did not preset the ext either; just left it to whatever the
          original is. If the tag is found empty or not in the correct
          format you will be told that. the file will be left open to
          manually rename it after the rest of them are done. The files
          will close after each one gets renamed.

          H=Titles2FileName
          ; Ntb-Clips-Subscribe@..., 10-10-1999, Jody
          ^!Clearvariables
          ^!SetHintInfo Renaming Files...
          ^!SetScreenUpdate Off
          ^!Document Last

          :Loop
          ^!Jump 1
          :Loop
          ^!Find "<TITLE>" SI
          ^!IfError Info
          ^!Jump Select_End
          ^!Set %Start%=^$GetRow$:^$GetCol$
          ^!Find "</TITLE>" SI
          ^!IfError Info
          ^!Jump Select_Start
          ^!SelectTo ^%Start%
          ^!Set %Title%=^$GetSelection$
          ^!Set %Title%=^$StrReplace("^%Tab%";"^%Empty%";"^%Title%";False;False)$
          ^!Set %Title%=^$StrReplace("^%nl%";"^%Empty%";"^%Title%";False;False)$
          ^!Set %Title%=^$StrTrim("^%Title%")$
          ^!Set %Title%=^$StrLower("^%Title%")$
          ^!IfTrue ^$IsEmpty("^$GetName("^%Title%")$")$ Info

          ^!RenameFile "^##" "^$GetPath(^##)$^%Title%^$GetExt(^##)$

          ^!IfTrue ^$GetDocIndex$ Skip_2
          ^!Close
          ^!Goto Loop
          ^!Close
          ^!Goto End

          :Info
          ^!Info [L]Part or all of the title was found missing or there was no data between the tags. The file will remain open so you may manually rename it after the rest are completed. Click OK to resume or press Ctrl+Alt and click OK to abort.
          ^!Document Prev
          ^!Goto Loop

          H=";----------------------------------------------"

          H="Switch2Doc#"
          ^!SetHintInfo Getting names and numbers...
          ^!Set %num%=0; %nDex%=0; %docs%=^%Empty%

          ^!Inc %num%
          ^!Inc %nDex%
          ^!Append %docs%=^%nDex%: ^$GetDocName(^%num%)$|
          ^!IF ^%num% < ^$GetDocCount$ Skip_-3

          ^!Set %docs%=^$StrDelete("^%docs%";^$StrSize("^%docs%")$;1)$
          ^!Set %Id%=^?{(H=28)Select==^%docs%}

          ^!IfDiff "^$StrCopy("^%Id%";2;1)$" ":" Skip_2
          ^!SetDocIndex ^$StrCopy("^%Id%";1;1)$
          ^!Goto End

          ^!IfDiff "^$StrCopy("^%Id%";3;1)$" ":" Skip_2
          ^!SetDocIndex ^$StrCopy("^%Id%";1;2)$
          ^!Goto End

          ^!IfDiff "^$StrCopy("^%Id%";4;1)$" ":" Skip_2
          ^!SetDocIndex ^$StrCopy("^%Id%";1;3)$

          H=";-----------------------------------------------"

          H="Doc_Start-All"
          ^!SetHintInfo Jumping...
          ^!SetScreenUpdate Off
          ^!Document Last
          ^!Jump 1
          ^!Document Prev
          ^!IfTrue ^$GetDocIndex$ Next else Skip_-2
          ^!Jump 1

          H="Doc_End-All"
          ^!SetHintInfo Jumping...
          ^!SetScreenUpdate Off
          ^!Document Last
          ^!Jump Doc_End
          ^!Document Prev
          ^!IfTrue ^$GetDocIndex$ Next else Skip_-2
          ^!Jump Doc_End

          H="Document First"
          ^!Document First
          ^!Jump 1

          H="Document Prev"
          ^!Document Prev
          ^!Jump 1

          H="Document Next"
          ^!Document Next

          H="Document Last"
          ^!Document Last
          ^!Jump 1

          H="Doc_Start"
          ^!Jump Doc_Start

          H="Doc_End"
          ^!Jump Doc_End

          H=";-----------------------------------------------"

          H="Read Only Kill"
          ^!attrib -r ^?[(T=D)Mark's directory file properties as non-Read Only=]*.*

          H=";-----------------------------------------------"


          Happy NoteTabbin',
          Jody Adair

          The NoteTabbers Assistant Page
          http://www.sureword.com/notetab
          NoteTab Home Page - Go Pro.....
          http://www.notetab.com

          ------------------------------------------------------------------------

          eGroups.com home: http://www.egroups.com/group/ntb-clips
          http://www.egroups.com - Simplifying group communications
        • Jody
          Hi Grant, Bong, and All, If you use my Clip on this thread you need to add the end quote on RenameFile, else they will not get renamed: ^!RenameFile ^##
          Message 4 of 4 , Jul 10 9:38 PM
          • 0 Attachment
            Hi Grant, Bong, and All,

            If you use my Clip on this thread you need to add the end quote
            on RenameFile, else they will not get renamed:

            ^!RenameFile "^##" "^$GetPath(^##)$^%Title%^$GetExt(^##)$"

            I had renamed it in the clip where I should have copied it from
            before posting. :(

            > Doing this sort of thing is bread and butter stuff for Notetab Pro.

            I got to looking at your clip and I believe you just about have
            the perfected one. I think I will take bits and pieces from both
            and add a bit so we can have a killer clip! :) Here are some
            notes, because I don't have the time at the moment to do it.
            After looking at your's some more I saw where it might be a tad
            bit faster than mine in their original states.

            >^!Set %FileSpecs%="*.htm"

            *.*htm* That will do all html files, if the command takes it and
            I am pretty sure it does, I just didn't check.

            :LoopDeLoop

            <vbg>

            ^!Open ^%File%

            Instead of opening the file which is where both our clips get
            bogged down at we can use RenameFile when the time comes.

            ^!Set %Str%=^$GetText$
            ^!Set %Str%=^$StrDelete(^%Str%;^$StrPos(</TITLE>;^%Str%;False)$;^$StrSize(^%Str%)$)$
            ^!Set %Str%=^$StrDelete(^%Str%;1;^$StrPosRight(>;^%Str%;False)$)$

            I started to think of how to do that and figured it wasn't worth
            my headache! I start getting confused when dealing with StrPos,
            size, count, etc.

            ; ^!RenameDoc ^%Str%

            Here is where we gain the speed, because it is not necassary to
            open and close the files since we already have the data needed to
            rename the file that was gathered using GetFileFirst/Next and
            ^$GetText$.

            ^!ReNameFile "^%File%" "^$GetPath(^%File%)$^%Str%^$GetExt(^%File%)$"

            I'm not sure about the variables, but you have the idea.

            ^!GoTo LoopDeLoop

            HeeHaw!

            c ya,
            jody

            I can only please one person a day.
            Today is obviously not your day.
            Tomorrow doesn't look good either. 8?D

            http://www.sureword.com/sojourner/

            ------------------------------------------------------------------------

            eGroups.com home: http://www.egroups.com/group/ntb-clips
            http://www.egroups.com - Simplifying group communications
          Your message has been successfully submitted and would be delivered to recipients shortly.