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

Processing directory of files: Need Advice

Expand Messages
  • Alan Williams
    Hi all Im trying to write a clip that will open each file in a directory, insert a file at a marker, do a find and replace using regular expression (am unable
    Message 1 of 3 , May 2, 2000
    View Source
    • 0 Attachment
      Hi all

      Im trying to write a clip that will open each file in a directory,
      insert a file at a marker, do a find and replace using regular
      expression (am unable to get it to be non-greedy or whatever).

      So far I have this:

      -----begin rudimentary clip-----
      = V5 MultiLine NoSorting TabWidth=30

      H="Process"

      ^!Set %newsf%=^$GetFileFirst(g:\her\news\;*.*)$
      ^!Open ^%newsf%
      ^!Find "<!-- hertophtml -->"
      ^!InsertFile g:\her\hertop.txt
      ^!Find "<!-- herendhtml -->"
      ^!InsertFile g:\her\herbot.txt
      ^!Jump TEXT_START
      ^!Replace "<!--.*--> " >> "??" [IRA]

      ----end rudimentary clip---------

      This does the job - except that the regex replace sometimes includes
      words between <!--...--> <!--...--> sequences. That is it does not
      check for one <!-- and then one --> and delete them and everything
      between them and then check for the next instance of <!-- and so on.
      (Does anyone have an idea on how to force it to be "non-greedy", I
      think the term is.)

      My next task is to make the clip above loop through all the files in
      the directory performing the same task on each one.

      Ive tried various combinations of labels. So far a few strange things
      happen. I have 3 files in my test directory, My modification below
      opens two of them, but does not perform the regex replace! In other
      variations it does the replace on the first file but not the other.

      ------------------------------------------------
      H="Process"

      ^!Set %newsf%=^$GetFileFirst(g:\her\news\;*.*)$
      ^!Open ^%newsf%
      ^!Find "<!-- hertophtml -->"
      ^!InsertFile g:\her\hertop.txt
      ^!Find "<!-- herendhtml -->"
      ^!InsertFile g:\her\herbot.txt
      ^!Jump TEXT_START
      ^!Replace "<!--.*--> " >> "??" [IRA] Goto Loop
      :Loop
      ^!Set %newsf%=^$GetFileNext$
      ^!Open ^%newsf%
      ^!Find "<!-- hertophtml -->"
      ^!InsertFile g:\her\hertop.txt
      ^!Find "<!-- herendhtml -->"
      ^!InsertFile g:\her\herbot.txt
      ^!Jump TEXT_START
      ^!Replace "<!--.*--> " >> "??" [IRA] Goto :Loop
      ------------------------------------------------

      What am I doing stupid here? Please advise.


      Best regards,
      Alan
      mailto:alwilli@...
    • Jody
      Hi Alan, ... It s hard for me tell exactly what you are doing, but I will comment on the following two lines first. ... Don t put the brackets around your
      Message 2 of 3 , May 3, 2000
      View Source
      • 0 Attachment
        Hi Alan,

        > Im trying to write a clip that will open each file in a
        > directory, insert a file at a marker, do a find and replace
        > using regular expression (am unable to get it to be non-greedy
        > or whatever).

        It's hard for me tell exactly what you are doing, but I will
        comment on the following two lines first.

        >^!Replace "<!--.*--> " >> "??" [IRA]

        Don't put the brackets around your options. The brackets in Help
        are only there to tell you the options are optional.

        >^!Replace "<!--.*--> " >> "??" [IRA] Goto Loop

        Goto Loop needs to be on its own line:

        ^!Goto Loop

        You seem to know enough to modify this to fit your needs, but
        perhaps you can just use the RegExp in Search Disk to do what you
        need.

        Find whatever and Replace with: <!--[^>]*-->

        That will select everything between the open/end arrows and not
        go to the next, as in only the abc comment below and then the def.

        <!-- abc --> <!-- def -->

        <--- Copy below this line --->
        H=OpenDir-RegExp-G
        ; Last Updated 05/03/2000, Sojourner@..., jody
        ; Requires NoteTab v4.81
        ; http://www.sureword.com/notetab

        ^!ClearVariables

        ; long line till blank line
        ^!Set %Folder%=^?{(T=D)Full path, end in backslash=E:\NoteTab Pro\Test\}; %Type%=^?{File &Type=*.htm*}; %Sort%=^?{&Sort order=Date|_Name|Size|Type|UnSorted}

        ^!SetHintInfo Opening Files...

        ^!SetListDelimiter ^p
        ^!SetArray %OpenList%=^$GetFiles("^%Folder%";^%Type%;^%Sort%)$
        ^!Set %Count%=^%OpenList0%
        ^!Set %Index%=0
        ^!Set %OpenCount%=0

        :OpenLoop
        ^!SetScreenUpdate Off
        ^!Inc %Index%
        ^!If ^%Index% > ^%Count% Replace
        ^!IfTrue ^%FileCnt% Skip
        ^!Open ^%OpenList^%Index%%
        ^!Goto OpenLoop

        :Replace
        ; change the replace side
        ^!Replace "<!--[^>]*-->" >> "<!-- www.sureword.com/notetab -->" WATIRSG
        ^!IfError End

        <--- Copy above this line, right --->
        <--- click over a Library, and --->
        <--- choose "Add from Clipboard" --->

        Happy Clip'n!
        Jody

        http://www.sureword.com/notetab

        Subscribe, UnSubscribe, Options
        mailto:Ntb-Clips-Subscribe@...
        mailto:Ntb-Clips-UnSubscribe@...
        http://www.egroups.com/list/ntb-clips
      • Jody
        Hi Alan, ... Reverse that please. :) Find ]*-- and replace with... nite... c ya, Jody The whole world doth err save you and me and even thou doest err
        Message 3 of 3 , May 3, 2000
        View Source
        • 0 Attachment
          Hi Alan,

          >Find whatever and Replace with: <!--[^>]*-->

          Reverse that please. :)

          Find <!--[^>]*--> and replace with...

          nite...

          c ya,
          Jody

          The whole world doth err save you
          and me and even thou doest err some!

          http://www.sureword.com/sojourner
        Your message has been successfully submitted and would be delivered to recipients shortly.