mIRC Home    About    Download    Register    News    Help

Topic Options
#198257 - 24/04/08 12:54 PM $findfile and /remove
dassa Offline
Ameglian cow

Registered: 31/01/08
Posts: 22
Hi
I am trying to cut files from the root mIRC dir to another dir. Problem is i have to run the alias a few times to get the desired results which is annoying as using /echo it echoes all of them. I cannot work out what the error is. I paste the code below and any suggestions will be very much appreciated.

Code:
alias cut.files {
  var %x = 1
  while ($findfile($mircdir,irc*,%x,1)) { 
    var %file = $qt($v1)
  if (%file != irc-companion) { copy -o %file $scriptdir($gettok(%file,-1,92)) | remove %file | inc %x } }
}

Top
#198258 - 24/04/08 01:10 PM Re: $findfile and /remove [Re: dassa]
Horstl Offline
Hoopy frood

Registered: 03/11/06
Posts: 1559
Loc: Germany
Every time you remove a file and inc the file-count %x, $findfile(dir,N) will not point at the next file but the file after the next file. The next file would be the file with the same number, as the "current" file with this number had been removed smile
To fix this, e.g. change your while loop to inc the number only if your (file != something)-condition is not met and the file has not been removed.

Code:
alias cut.files {
  var %x = 1
  while ($findfile($mircdir,test*,%x,1)) { 
    var %file = $qt($v1)
    if (%file != $qt($+($mircdir,testing.txt))) {
      copy -o %file $+($scriptdir,$nopath(%file))
      remove %file 
    }
    else { inc %x }
  }
}

Edit: Note that - now - this should pass all files correctly if you execute the copy/remove command, but will result in an infinite loop if you echo the command only.


Edited by Horstl (24/04/08 01:29 PM)

Top
#198259 - 24/04/08 02:50 PM Re: $findfile and /remove [Re: dassa]
genius_at_work Offline
Hoopy frood

Registered: 08/10/05
Posts: 1741
To solve the problem mentioned by Horstl, you can use a decreasing loop instead of an increasing one.

Code:

alias cut.files {
  var %x = $calc($findfile($mircdir,irc*,0,1) + 1), %xx = 1
  while (%x > %xx) {
    dec %x
    var %file = $qt($findfile($mircdir,irc*,%x,1))
    if (%file != irc-companion) { 
      copy -o %file $scriptdir($gettok(%file,-1,92)) 
      remove %file
    } 
  }
}


(untested)

-genius_at_work

Top
#198263 - 24/04/08 03:08 PM Re: $findfile and /remove [Re: dassa]
qwerty Offline
Hoopy frood

Registered: 07/01/03
Posts: 2523
Quite a few problems with that code.
  • /inc %x should be inside an /else, corresponding to your /if: if the file is moved, %x should not be incremented, for the reason explained by Horstl. Otherwise, %x should be incremented.
  • %file will never equal "irc-companion" because it is the full filename, including the path (eg it would look like "C:\Program files\mIRC\irc-companion")
  • $scriptdir does not accept parameters. You just need $+ to concatenate $scriptdir with the filename.
However, this method of using $findfile is very inefficient and will cause noticeable delay if you have relatively many files in $mircdir. Here's a simpler and faster way, that also shows how to use /rename to move files directly. This has the advantage that if $scriptdir is on the same partition as $mircdir, no copying of data is performed: the files are moved directly, which is much faster and doesn't require extra disk space.

Code:
alias cut.files {
  return $findfile($mircdir,irc*,0,1,if ($nopath($1-) != irc-companion) rename $qt($1-) $qt($scriptdir $+ $v1)))
}

If you don't want to see the * Renamed blahblah message, prefix the /rename command with a dot.

There is one potential problem with /rename: I noticed you're using the -o switch in /copy to force an overwrite if the destination exists. /rename does not offer this functionality, so if this is important, you'll have to first delete the destination file, if it exists. To do that, you'd have to create an alias that contains a /remove and then a /rename and use that inside $findfile.
_________________________
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com

Top
#198264 - 24/04/08 03:28 PM Re: $findfile and /remove [Re: dassa]
RoCk Offline
Hoopy frood

Registered: 16/12/02
Posts: 2009

Well here's my contribution, which I made before seeing qwerty's method (his is much better).

Code:

alias cut.files {
  if (%cut.files) {
    if ($nopath($1) != irc-companion) {
      if ($isfile($+($scriptdir,$nopath($1)))) .remove $qt($+($scriptdir,$nopath($1)))
      .rename $qt($1) $qt($+($scriptdir,$nopath($1)))
    }
    return
  }
  set %cut.files $true
  window -hl @cut.files
  noop $findfile($mircdir,irc*,0,0,@cut.files)
  filter -wk @cut.files cut.files *
  unset %cut.files
  window -c @cut.files
}



~ Edit ~
Imagining using the if statement in the command section of $findfile would have made all the difference for me lol. Ahh well. Very nicely done as usual qwerty.
smile

~ Edit ~
Added the
/remove per qwerty's suggestion so no second alias is necessary.

Top
#198293 - 25/04/08 10:54 AM Re: $findfile and /remove [Re: RoCk]
dassa Offline
Ameglian cow

Registered: 31/01/08
Posts: 22
wow thanks for all the replies. qwerty i like you approach alot and thanks for that.

Top