|
Joined: Jan 2008
Posts: 22
Ameglian cow
|
OP
Ameglian cow
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. 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 } }
}
|
|
|
|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
Hoopy frood
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 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. 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.
|
|
|
|
Joined: Oct 2005
Posts: 1,741
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,741 |
To solve the problem mentioned by Horstl, you can use a decreasing loop instead of an increasing one.
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
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
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. 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
|
|
|
|
Joined: Dec 2002
Posts: 2,031
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,031 |
Well here's my contribution, which I made before seeing qwerty's method (his is much better).
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. ~ Edit ~ Added the /remove per qwerty's suggestion so no second alias is necessary.
|
|
|
|
Joined: Jan 2008
Posts: 22
Ameglian cow
|
OP
Ameglian cow
Joined: Jan 2008
Posts: 22 |
wow thanks for all the replies. qwerty i like you approach alot and thanks for that.
|
|
|
|
|