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

Re: [Clip] clip to save all index.html as index.htm

Expand Messages
  • Axel Berger
    ... Possibly. But just this is one of the standard tasks for Totalcommander, a utility I can t do without so much, that I hide an unregistered copy somewhere
    Message 1 of 12 , Nov 1, 2006
      Mike Breiding wrote:
      > Would it be possible to write a clip which would check all directories for
      > the presence of index.html and then make a copy of this file and have it to
      > file named index.htm?

      Possibly. But just this is one of the standard tasks for Totalcommander,
      a utility I can't do without so much, that I hide an unregistered copy
      somewhere on every machine I'm ever asked to help with a problem on.
      N.B: Apart from one nag screen the demo is fully functional.

      Axel
    • Veli-Pekka Tätilä
      ... I d write this either in PErl or using batch commands. Here are both options and both can be run on the command-line. Be sure to make backups before
      Message 2 of 12 , Nov 2, 2006
        Mike Breiding wrote:
        > <snip> check all directories for index.html and make a copy to index.htm?
        I'd write this either in PErl or using batch commands. Here are both
        options and both can be run on the command-line. Be sure to make backups
        before running, as I've only tested this with some dummy data.

        The Perl Command-lien version goes like this:

        perl -wMFile::Find -e "find sub{/^(index)\.(htm)l$/i and (system 'copy', $_,
        qq|$1.$2|) and warn qq|$_: $^E|}, '.'"

        Run it in the dir in which you'd like to start renaming. COmmand-lien apps
        in DOS assume the dir to which you've CDed as their working directory. The
        script isn't portable outside of WIn32. To make it such you'd have to
        include the File::Copy module, too. I'd put it in a file if it gets any
        longer, though.

        The native Windows/DOS way is potentially much more interesting as it
        doesn't need Perl. You gotta run this on the command-line and put the
        command in a single line:

        for /f "usebackq delims=" %a in (`dir /s /b index.html`) do copy "%a"
        "%~dpna.htm"

        Taking that token by token:

        for: let's you run a command repeatedly for a set of files or lines.

        /f: allows you to pass XP specific options not supported in DOS.

        "usebackq delims=": Tells that we'd like to use back quotes for capturing
        the output of a command line by line as opposed to a list of file names
        matching a Wildcard pattern. Normally for /f splits the data on a line or
        file name into tokens or fields if you will, space separated. We set the
        separator to the empty string to make the variable %a slurp the whole line.

        %a: the variable representing the current line. You'll need to double the
        percent signs if you put this in a batch file.

        in: a reserved word must be present.

        (`dir /s /b index.html`): RUns the dir command fetching the full paths of
        all files that match case insensitively index.html. The wild cards in dir
        assume that the file starts with index and ends with html exactly.

        do: another reserved word separating the command from the other arguments.
        If you'd like to test without copying append @echo after this word to echo
        stuff on screen in stead of executing commands.

        copy: The DOS command.

        "%a": Full path of original file. Must be double-quoted to handle spaces
        properly.

        "%~dpna.htm": This is WIndows specific notation. The contents of %a
        interpretted as the drive letter, path, and basename of the file in %a plus
        a new extension .htm.

        Hope this helps.

        --
        With kind regards Veli-Pekka Tätilä (vtatila@...)
        Accessibility, game music, synthesizers and programming:
        http://www.student.oulu.fi/~vtatila/
      • Mike Breiding
        ... Whew! That s a plate full for a command line dummy like me. I will se if I can twist my brain around it. Thanks for taking the time to work on this.
        Message 3 of 12 , Nov 2, 2006
          At 01:31 PM 11/2/2006 , you wrote:
          >Mike Breiding wrote:
          > > <snip> check all directories for index.html and make a copy to index.htm?
          >I'd write this either in PErl or using batch commands. Here are both
          >options and both can be run on the command-line. Be sure to make backups
          >before running, as I've only tested this with some dummy data.

          <snip>
          Whew!
          That's a plate full for a command line dummy like me.

          I will se if I can twist my brain around it.

          Thanks for taking the time to work on this.

          -Mike


          ----------
          Check it out:
          www.EpicRoadTrips.us

          [Non-text portions of this message have been removed]
        • hsavage
          ... directories for ... it to ... Mike, I m a regex novice, as most of us are, so, a clip language solution to this is more easily understood. If I understand
          Message 4 of 12 , Nov 2, 2006
            Mike Breiding wrote:
            > Greetings,
            > Would it be possible to write a clip which would check all
            directories for
            > the presence of index.html and then make a copy of this file and have
            it to
            > file named index.htm?
            >
            > Thanks,
            > -Mike

            Mike,

            I'm a regex novice, as most of us are, so, a clip language solution to
            this is more easily understood.

            If I understand correctly you want to rename all occurrences of
            'INDEX.HTML' to 'INDEX.HTM', is that right?

            With the following clip you can do that and it gives you the option of
            choosing which drive to do to do the renaming on. Give it a try if you
            want.

            *******************
            H="Change INDEX.HTML > HTM"
            ;_ Modified-Updated~Created_20061102
            ;_ hrs ø hsavage·pobox·com_02:39:31p
            ^!ClearVariables
            ^!SetWizardTitle "Select 'Drive ' to Scan for INDEX.HTML Files"
            ^!Set %drv%=^?{(T=D)Drive to Scan for INDEX.HTML=C:\}
            ^!SetListDelimiter ^%nL%
            ; this was a test line to check another drive, 'E:\'
            ;^!SetArray %ndxhtml%="^$StrTrim(^$GetDosOutput(dir/-p/a/b/on/s
            ^%drv%Twinky.HTML)$)$"
            ^!SetArray %ndxhtml%="^$StrTrim(^$GetDosOutput(dir/-p/a/b/on/s
            ^%drv%INDEX.HTML)$)$"
            ^!Set %pfnl%=0
            :FILELIST
            ^!Inc %pfnl%
            ^!RenameFile "^%ndxhtml^%pfnl%%" "^$StrDeleteRight("^%ndxhtml^%pfnl%%";1)$"
            ; creates a variable to display changed names in ^!Info [L] box.
            ;^!Append %changed%="^$StrDeleteRight("^%ndxhtml^%pfnl%%";1)$"^%nL%
            ^!If ^%pfnl% < ^%ndxhtml0% FILELIST
            ;^!Info [L]^%changed%
            ************************

            ºvº
            2006.11.02
            -Newspaper HeadLine...
            "British Union Finds Dwarfs in Short Supply"
            hrs ø hsavage@...
          • Mike Breiding
            ... Greetings, Actually, I want to copy all files named index.html to files named index.htm, not just rename them. In other words the subdirs with only
            Message 5 of 12 , Nov 2, 2006
              At 04:39 PM 11/2/2006 , hsavage wrote:
              >Mike,
              >
              >I'm a regex novice, as most of us are, so, a clip language solution to
              >this is more easily understood.
              >
              >If I understand correctly you want to rename all occurrences of
              >'INDEX.HTML' to 'INDEX.HTM', is that right?

              Greetings,

              Actually, I want to copy all files named index.html to files named
              index.htm, not just rename them.

              In other words the subdirs with only index.html would then contain an
              additional file, a copy of index.html which would be named index.htm.

              So it is both a copy and rename task.

              Thanks!

              -Mike




              [Non-text portions of this message have been removed]
            • hsavage
              ... Mike, Very easily done with a change to the ^!RenameFile line. Changed, tested, clip below! *************** H= Copy INDEX.HTML HTM ;_
              Message 6 of 12 , Nov 2, 2006
                Mike Breiding wrote:
                > At 04:39 PM 11/2/2006 , hsavage wrote:
                >> Mike,
                >>
                >> If I understand correctly you want to rename all occurrences of
                >> 'INDEX.HTML' to 'INDEX.HTM', is that right?
                >
                > Greetings,
                >
                > Actually, I want to copy all files named index.html to files named
                > index.htm, not just rename them.
                >
                > In other words the subdirs with only index.html would then contain an
                > additional file, a copy of index.html which would be named index.htm.
                >
                > So it is both a copy and rename task.
                >
                > Thanks!
                >
                > -Mike

                Mike,

                Very easily done with a change to the ^!RenameFile line. Changed,
                tested, clip below!

                ***************
                H="Copy INDEX.HTML > HTM"
                ;_ Modified-Updated~Created_20061102
                ;_ hrs ø hsavage·pobox·com_02:39:31p
                ^!ClearVariables
                ^!SetWizardTitle "Select 'Drive ' to Scan for INDEX.HTML Files"
                ^!Set %drv%=^?{(T=D)Drive to Scan for INDEX.HTML=C:\}
                ^!SetListDelimiter ^%nL%
                ; this was a test line to check another drive, 'E:\'
                ;^!SetArray %ndxhtml%="^$StrTrim(^$GetDosOutput(dir/-p/a/b/on/s
                ^%drv%Twinky.HTML)$)$"
                ^!SetArray %ndxhtml%="^$StrTrim(^$GetDosOutput(dir/-p/a/b/on/s
                ^%drv%INDEX.HTML)$)$"
                ^!Set %pfnl%=0
                ; ·····
                ^!SetDebug 1
                ; -----
                :FILELIST
                ^!Inc %pfnl%
                ^!CopyFile "^%ndxhtml^%pfnl%%" "^$StrDeleteRight("^%ndxhtml^%pfnl%%";1)$"
                ;^!RenameFile "^%ndxhtml^%pfnl%%" "^$StrDeleteRight("^%ndxhtml^%pfnl%%";1)$"
                ; creating a variable to display changed names in ^!Info [L] box.
                ;^!Append %changed%="^$StrDeleteRight("^%ndxhtml^%pfnl%%";1)$"^%nL%
                ^!If ^%pfnl% < ^%ndxhtml0% FILELIST
                ;^!Info [L]^%changed%
                ********************

                ºvº
                2006.11.02
                -Newspaper HeadLine...
                "British Union Finds Dwarfs in Short Supply"
                hrs ø hsavage@...
              • Mike Breiding
                ... ============= Works great! Thanks, -Mike [Non-text portions of this message have been removed]
                Message 7 of 12 , Nov 3, 2006
                  At 06:29 PM 11/2/2006 , you wrote:
                  ><trim>
                  > > So it is both a copy and rename task.
                  > > Thanks!> -Mike
                  >
                  >Mike,
                  >Very easily done with a change to the ^!RenameFile line. Changed,
                  >tested, clip below!
                  >***************
                  >H="Copy INDEX.HTML > HTM"
                  >;_ Modified-Updated~Created_20061102
                  >;_ hrs ø hsavage·pobox·com_02:39:31p
                  >^!ClearVariables
                  >^!SetWizardTitle "Select 'Drive ' to Scan for INDEX.HTML Files"
                  >^!Set %drv%=^?{(T=D)Drive to Scan for INDEX.HTML=C:\}
                  >^!SetListDelimiter ^%nL%
                  >; this was a test line to check another drive, 'E:\'
                  >;^!SetArray %ndxhtml%="^$StrTrim(^$GetDosOutput(dir/-p/a/b/on/s
                  >^%drv%Twinky.HTML)$)$"
                  >^!SetArray %ndxhtml%="^$StrTrim(^$GetDosOutput(dir/-p/a/b/on/s
                  >^%drv%INDEX.HTML)$)$"
                  >^!Set %pfnl%=0
                  >; ·····
                  >^!SetDebug 1
                  >; -----
                  >:FILELIST
                  >^!Inc %pfnl%
                  >^!CopyFile "^%ndxhtml^%pfnl%%" "^$StrDeleteRight("^%ndxhtml^%pfnl%%";1)$"
                  >;^!RenameFile "^%ndxhtml^%pfnl%%" "^$StrDeleteRight("^%ndxhtml^%pfnl%%";1)$"
                  >; creating a variable to display changed names in ^!Info [L] box.
                  >;^!Append %changed%="^$StrDeleteRight("^%ndxhtml^%pfnl%%";1)$"^%nL%
                  >^!If ^%pfnl% < ^%ndxhtml0% FILELIST
                  >;^!Info [L]^%changed%
                  >********************
                  >ºvº
                  >2006.11.02
                  >-Newspaper HeadLine...
                  >"British Union Finds Dwarfs in Short Supply"
                  >hrs ø
                  ><mailto:hsavage%40pobox.com>hsavage@pobox.<mailto:hsavage%40pobox.com>com

                  =============
                  Works great!

                  Thanks,
                  -Mike





                  [Non-text portions of this message have been removed]
                • abairheart
                  ... index.htm? ... Yes, DOS is the more efficient way to go, but you do not need to loop to get the job done, if you use XCOPY. Let DOS/Windows do the hard
                  Message 8 of 12 , Nov 5, 2006
                    --- In ntb-clips@yahoogroups.com, Veli-Pekka Tätilä <vtatila@...> wrote:
                    >
                    > Mike Breiding wrote:
                    > > <snip> check all directories for index.html and make a copy to
                    index.htm?

                    > The native Windows/DOS way is potentially much more interesting as it
                    > doesn't need Perl. You gotta run this on the command-line and put the
                    > command in a single line:
                    >
                    > for /f "usebackq delims=" %a in (`dir /s /b index.html`) do copy "%a"
                    > "%~dpna.htm"
                    >


                    Yes, DOS is the more efficient way to go, but you do not need to loop
                    to get the job done, if you use XCOPY. Let DOS/Windows do the hard
                    stuff. See the sample clip below.

                    Here is an excerpt from XCOPY help:

                    XCOPY source [destination] /S /C /Q [/L] [/H] /Y

                    source Specifies the file(s) to copy.
                    destination Specifies the location and/or name of new files.
                    /S Copies directories and subdirectories except empty ones.
                    /C Continues copying even if errors occur.
                    /Q Does not display file names while copying.
                    /F Displays full source and destination file names while
                    copying.
                    /L Displays files that would be copied.
                    /H Copies hidden and system files also.
                    /Y Suppresses prompting to confirm you want to overwrite


                    The ONE thing you must do is set the path in your clip before you
                    execute the XCOPY command, otherwise, the destination files will not
                    go to the correct folder.

                    Use something like

                    H="html to html plus htm"
                    ^!Set %path%=site's root path (wizard or hard-code)
                    ^!ChDr ^%path%
                    ^!Dos "^%path%index.html" *.htm /S /C /Q /H /Y

                    That's it. It will do the entire tree of files, if you want to TEST
                    the result first, replace the /Q switch with the /L switch. Files will
                    not actually get copied, but displayed in the commandline window.

                    One more trick:

                    append the DOS command with a "&pause" to keep the commandline window
                    OPEN, when testing, so you can inspect the result at leisure.

                    ^!Dos "^%path%index.html" *.htm /S /C /L /H /Y&pause


                    Abair
                  Your message has been successfully submitted and would be delivered to recipients shortly.