mIRC Home    About    Download    Register    News    Help

Print Thread
$findfile and /remove #198257 24/04/08 11:54 AM
Joined: Jan 2008
Posts: 22
D
dassa Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Jan 2008
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 } }
}

Re: $findfile and /remove [Re: dassa] #198258 24/04/08 12:10 PM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
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.

Last edited by Horstl; 24/04/08 12:29 PM.
Re: $findfile and /remove [Re: dassa] #198259 24/04/08 01:50 PM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
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

Re: $findfile and /remove [Re: dassa] #198263 24/04/08 02:08 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
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
Re: $findfile and /remove [Re: dassa] #198264 24/04/08 02:28 PM
Joined: Dec 2002
Posts: 2,010
R
RoCk Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,010

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.

Re: $findfile and /remove [Re: RoCk] #198293 25/04/08 09:54 AM
Joined: Jan 2008
Posts: 22
D
dassa Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Jan 2008
Posts: 22
wow thanks for all the replies. qwerty i like you approach alot and thanks for that.