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

Re: [Clip] remove all .bak files in directory structure

Expand Messages
  • loro
    ... Not sure if you mean the clip doesn t do sub directories? It does. Or was there something else wrong? I m a sloppy copy-paster. Lotta
    Message 1 of 13 , Jan 27, 2010
    • 0 Attachment
      Axel Berger wrote:
      >loro wrote:
      > > Does now.
      >
      >Not quite
      >
      > > Don wrote:
      > > >and in it's sub-directories

      Not sure if you mean the clip doesn't do sub directories? It does. Or
      was there something else wrong? I'm a sloppy copy-paster.

      Lotta
    • Don - HtmlFixIt.com
      ^!SetListDelimiter ^p ;EDIT THE PATH BELOW ^!Set %file_path%= ^?{(T=D)CHOOSE FOLDER CONTAINING SUBJECT FILES=C: Documents and Settings User My Documents } ;
      Message 2 of 13 , Jan 27, 2010
      • 0 Attachment
        ^!SetListDelimiter ^p
        ;EDIT THE PATH BELOW
        ^!Set %file_path%="^?{(T=D)CHOOSE FOLDER CONTAINING SUBJECT
        FILES=C:\Documents and Settings\User\My Documents\}"; %sub%="^?{SHOW
        SUBFOLDERS==_YES^=+|NO^=^%empty%}"

        ^!SetArray %bak%=^$GetFiles("^%sub%^%file_path%";"*.bak";Name)$
        ^$GetFiles("+C:\Documents and Settings\Don\My
        Documents\1b\1spencer\calendar\";"*.bak";Name)$
        ^!Set %cntr%=0
        :loop
        ^!Inc %cntr%
        ^!DeleteFile ^%bak^%cntr%%
        ^!If ^%cntr% < ^%bak0% loop else fin

        :fin
        ^!If ^%bak0% > 0 next else empty
        ^!Info [L]The following files were deleted:^p^%bak%
        ^!Goto end
        :empty
        ^!Info [L]No files found.

        loro wrote:
        > Don wrote:
        >> I wish to remove all .bak file in a particular directory and in it's
        >> sub-directories
        >>
        >> Does this clip exist?
        >
        >
        > Does now.
        >
        > ________________________________________
        >
        > h="Delete bak files"
        >
        > ^!SetListDelimiter ^p
        > ;EDIT THE PATH BELOW
        > ^!SetArray %bak%=^$GetFiles("+C:\path\to";*.bak)$
        >
        > ^!Set %cntr%=0
        > :loop
        > ^!Inc %cntr%
        > ^!DeleteFile ^%bak^%cntr%%
        > ^!If ^%cntr% < ^%bak0% loop else fin
        >
        > :fin
        > ^!If ^%bak0% > 0 next else empty
        > ^!Info [L]The following files were deleted:^p^%bak%
        > ^!Goto end
        > :empty
        > ^!Info [L]No files found.
        > ________________________________________
        >
        >
        > Or use ^!RecycleFile rather than ^!DeleteFile if you are a wimp! :-P
        >
        > Lotta
        >
        >
        >
        > ------------------------------------
        >
        > Fookes Software: http://www.fookes.com/
        > NoteTab website: http://www.notetab.com/
        > NoteTab Discussion Lists: http://www.notetab.com/groups.php
        >
        > ***
        > Yahoo! Groups Links
        >
        >
        >
        >
      • Al
        ... ... Er, uh, if you want automation, just use Linux. find .
        Message 3 of 13 , Jan 28, 2010
        • 0 Attachment
          Axel Berger wrote:
          > Al wrote:
          <snip "PC is for automation" -- and -- the win_doze manual method
          find/delete>
          > Apart
          > from that your solution is identical to mine.
          >
          <grin>

          Er, uh, if you want automation, just use Linux.

          find . -name '*.bak' -type f -exec rm {} \;

          The above one liner is your power clip on steroids just for this here
          task right here (how many lines of clip code are replaced by this one
          liner?). It's called commands that run in the bash shell.

          The Linux bash shell is programmable.
          --

          pwd = print working directory

          ls = equivalent to the Win "dir" command

          Hang out in the bash shell. The order of the next, 3 files in the
          directory. Then run the one liner. Now the .bak files are gone,
          leaving only the .txt file.

          al@P5Q:~/temp/tst$
          al@P5Q:~/temp/tst$ pwd
          /home/al/temp/tst
          al@P5Q:~/temp/tst$ ls
          me.bak tye.bak uno.txt
          al@P5Q:~/temp/tst$ find . -name '*.bak' -type f -exec rm {} \;
          al@P5Q:~/temp/tst$ ls
          uno.txt
          al@P5Q:~/temp/tst$

          Alan.
        • loro
          Don, Aha, maybe you are interested in the full monty. This is old and probably isn t thoroughly tested, but so far it has worked without accidents. I use it
          Message 4 of 13 , Jan 28, 2010
          • 0 Attachment
            Don,

            Aha, maybe you are interested in the full monty. This is old and
            probably isn't thoroughly tested, but so far it has worked without
            accidents. I use it for house cleaning. I tried to tidy it up a
            little now and I think it's fine. Anyway, you are now warned. :-)


            Follows clip that deletes, permanently deletes, copies and move files.
            _________________________________________

            h="File Move/Copy/Delete"

            ;#######################################################
            ;### Note that if files are MOVED or COPIED ###
            ;### to a new directory and a file with the same ###
            ;### name already exists, the file in the destina- ###
            ;### tion directory will be replaced with the moved ###
            ;### file without warning, but the old file can be ###
            ;### found in the recycle bin. ###
            ;#######################################################

            ^!Set %path%=^?[(T=D)Choose directory=c:\]
            ^!Set %subs%=^?[(T=C)Scan sub directories?==yes^=+|_no^=]
            ; long line follows
            ^!Set %ext%=^?[Look for files of the
            type...=.txt|.otl|.html|_.bak|efo~^=efo~*.*]
            ; long line follows
            ^!Set %result%=^?[See list of the files that were manipulated?=_yes|no]
            ; long line follows
            ^!Set %do_what%=^?[What to do with the files...=_delete
            (bin)^=RecycleFile|move^=MoveFile|copy^=CopyFile|delete
            permanently^=DeleteFile]
            ; end long lines


            ^!SetListDelimiter ^p
            ^!Set %files%=^$GetFiles("^%subs%^%path%";*^%ext%)$
            ^!SetArray %files%=^%files%
            ^!If ^%files0% =^%empty% empty

            ^!If ^%do_what% = RecycleFile del
            ^!If ^%do_what% = DeleteFile del else move


            :del
            ^!Set %cntr%=0
            :loop1
            ^!Inc %cntr%
            ^!^%do_what% ^%files^%cntr%%
            ^!If ^%cntr% < ^%files0% loop1 else fin

            :move
            ^!Set %dest%=^?{(T=D)Choose the destination directory=^%path%}
            ^!Set %cntr%=0
            :loop2
            ^!Inc %cntr%
            ^!^%do_what% "^%files^%cntr%%" "^%dest%"
            ^!If ^%cntr% < ^%files0% loop2 else fin


            :fin
            ^!If ^%do_what%=RecycleFile next else skip_2
            ^!Set %what%=deleted to the bin
            ^!Goto nfo
            ^!If ^%do_what%=MoveFile next else skip_2
            ^!Set %what%=moved to ^%dest%
            ^!Goto nfo
            ^!If ^%do_what%=CopyFile next else skip_2
            ^!Set %what%=copied to ^%dest%
            ^!Goto nfo
            ^!Set %what%=permanently deleted


            :nfo
            ^!Info [L]The following files were ^%what%:^p^p^%files%
            ^!Goto end
            :empty
            ^!Info [L]No files found.
            __________________________________________
          • loro
            I knew I had screwed up somewhere. Always do. I thought I was smart when I put the wild card asterisk in this line. ^!Set
            Message 5 of 13 , Jan 28, 2010
            • 0 Attachment
              I knew I had screwed up somewhere. Always do. I thought I was smart
              when I put the wild card asterisk in this line.
              ^!Set %files%=^$GetFiles("^%subs%^%path%";*^%ext%)$

              But that made the ^$GetFiles()$ function find files like
              telefonlista.txt when searching for efo~files . So the asterisk need
              to be moved into the array instead for the extensions that need them,
              so efo~ doesn't get one. I'll paste the corrected clip below. Hope I
              got it right now.

              Anyway, this is very odd. Neither when using Window's search
              or Notatab's disk search are the wrong files found when searching
              for "*efo~*.*". I wonder if the tilde is ignored all together with
              ^$GetFiles()$? (One minute later...). Yup. Looks that way.
              ^$GetFiles(C:\some\path\;*~*)$ finds all files in there. None of them
              has a tilde. Go figure.

              Lotta


              Corrected clip below.

              ______________________________________

              h="File Move/Copy/Delete"

              ;#######################################################
              ;### Note that if files are MOVED or COPIED ###
              ;### to a new directory and a file with the same ###
              ;### name already exists, the file in the destina- ###
              ;### tion directory will be replaced with the moved ###
              ;### file without warning, but the old file can be ###
              ;### found in the recycle bin. ###
              ;#######################################################

              ^!Set %path%=^?[(T=D)Choose directory=c:\]
              ^!Set %subs%=^?[(T=C)Scan sub directories?==yes^=+|_no^=]
              ; long line follows
              ^!Set %ext%=^?[Look for files of the
              type...=*.txt|*.otl|*.html|_*.bak|efo~^=efo~*.*]
              ; long line follows
              ^!Set %result%=^?[See list of the files that were manipulated?=_yes|no]
              ; long line follows
              ^!Set %do_what%=^?[What to do with the files...=_delete
              (bin)^=RecycleFile|move^=MoveFile|copy^=CopyFile|delete
              permanently^=DeleteFile]
              ; end long lines


              ^!SetListDelimiter ^p
              ^!Set %files%=^$GetFiles("^%subs%^%path%";^%ext%)$
              ^!SetArray %files%=^%files%
              ^!If ^%files0% =^%empty% empty

              ^!If ^%do_what% = RecycleFile del
              ^!If ^%do_what% = DeleteFile del else move


              :del
              ^!Set %cntr%=0
              :loop1
              ^!Inc %cntr%
              ^!^%do_what% ^%files^%cntr%%
              ^!If ^%cntr% < ^%files0% loop1 else fin

              :move
              ^!Set %dest%=^?{(T=D)Choose the destination directory=^%path%}
              ^!Set %cntr%=0
              :loop2
              ^!Inc %cntr%
              ^!^%do_what% "^%files^%cntr%%" "^%dest%"
              ^!If ^%cntr% < ^%files0% loop2 else fin


              :fin
              ^!If ^%do_what%=RecycleFile next else skip_2
              ^!Set %what%=deleted to the bin
              ^!Goto nfo
              ^!If ^%do_what%=MoveFile next else skip_2
              ^!Set %what%=moved to ^%dest%
              ^!Goto nfo
              ^!If ^%do_what%=CopyFile next else skip_2
              ^!Set %what%=copied to ^%dest%
              ^!Goto nfo
              ^!Set %what%=permanently deleted

              :nfo
              ^!If ^%files0% > 0 next else empty
              ^!Info [L]The following files were ^%what%:^p^P^%files%
              ^!Goto end
              :empty
              ^!Info [L]No files found.
              ______________________________________
            Your message has been successfully submitted and would be delivered to recipients shortly.