mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2007
Posts: 234
M
MTec007 Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Feb 2007
Posts: 234
I need to search all files in a directory for a string "No such paste:" and delete those files if the string is found.

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Code:
var %a = 1, %b = $findfile(c:\,*.*,0)
while %a <= %b {
  if $read($findfile(c:\,*.*,%a),w,No such paste:) {
    .remove $findfile(c:\,*.*,%a)
    dec %b
  }
  inc %a
}

untested, but should work. Modify c:\ for the actual drive and directory that you want to search, and *.* for the file type if you want to only search certain file types.

see /help $findfile for more information regarding specifying multiple file types.

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Another approach with prompts (using findfile for the loop and filter).
Start the command "/delfiles" - You will be prompted for the dir and expression. To play a bit save, the files will be moved to the recycle bin.
If you want to hide the display of removed files, replace "REMOVE -b $1-" with: ".REMOVE -b $1-" (prefixed with a dot).
To kill the files instantly, take out the "-b" parameter in this line.

Code:
alias delfiles {

  ; ---- your default values ----
  ; default directory for the directory prompt, e.g. "var %start = C:"
  var %start = C:
  ; default expression for the expression prompt, e.g. "var %default = No such paste:". You may leave it empty.
  var %default = No such paste:

  ; ---- don't edit below if you don't know what you do ----
  var %dir = $qt($$sdir(%start,Select a directory (Subdirectories won't be processed)))
  set -u %delfiles.xp $+(*,$$input(Enter expression (Plaintext search, wildcard matching. You may use wildcards inside the expression.): $&
    $crlf $crlf $+ All matching files will be removed!,eg,Delete all matching files in %dir,%default),*)
  set -u %delfiles.n 0
  var %total = $findfile(%dir,*,0,0,delfiles.filter $qt($1-))
  echo -a Done. Found and deleted %delfiles.n files matching $qt(%delfiles.xp) in the directory %dir (Processed files: %total $+ ).
}

alias -l delfiles.filter {
  filter -ffb $1- nul %delfiles.xp 
  if ($filtered) {
    REMOVE -b $1-
    inc %delfiles.n
  }
}


Joined: Feb 2007
Posts: 234
M
MTec007 Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Feb 2007
Posts: 234
thanks. works great. the second code works without freezing mirc, so thats a plus lol

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
If there are many and/or very large files, it will freeze, but a bit less... (mIRC is a single-threaded application) smile

Joined: Feb 2007
Posts: 234
M
MTec007 Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Feb 2007
Posts: 234
many many ~20kb files lol. yeah mirc does have limitations but it is also useful in doing things like this automatically, as where i might have to use batch scripting instead if not for mirc.


Link Copied to Clipboard