mIRC Home    About    Download    Register    News    Help

Print Thread
aliases (test for last file name) #138076 23/12/05 09:03 PM
Joined: Nov 2005
Posts: 11
S
sparkicks Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: Nov 2005
Posts: 11
ok basicly there should be a number of files names with
name001
name002
etc after them now i make a program to see how many there are or what the last one was.
Code:
gunznum {
  set %filenum 002
  set %keepgoing 1
  while (keepgoing == 1 ) {
    if ("W:\gcapture\gunz $+ %filenum  == $null) {
      set %returnv $calc(%keepgoing - 1)
      return returnv
      break
      set %keepgoing 0
    }
    else {
      inc filenum 
    }
  }
} 

now in remote
Code:
on *:TEXT:request*:?: {  
  if ($2 == gunz) {
   
    notice $nick there are $gunznum of files available
  } 
}


all looks fine

now why do i get this back then?
notice - there are of files available

Re: aliases (test for last file name) #138077 23/12/05 09:08 PM
Joined: Nov 2005
Posts: 42
A
Aenei Offline
Ameglian cow
Offline
Ameglian cow
A
Joined: Nov 2005
Posts: 42
You get that because the alias is returning a null value.

If that is the exact code you are using, I suggest you change the line
Code:
      return returnv
to return the variable:
Code:
      return %returnv
Note the % sign in the second.
Does that work?

Additionally you can probably do it much more easily by using $findfile, with N = 0 to return the number
Code:
$findfile(dir,wildcard,N,depth,@window | command)
so you need soemthing like
Code:
 $findfile($scriptdir,name*.txt,0)
should return the number of name*.txt files in the path to your script.

Last edited by Aenei; 23/12/05 09:12 PM.
Re: aliases (test for last file name) #138078 23/12/05 09:19 PM
Joined: Nov 2005
Posts: 11
S
sparkicks Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: Nov 2005
Posts: 11
na doesnt make a difference i tried it with % ... no difference...


btw the findfile doesnt work... it says invalad parameters
erm... as a mattter of intrest will mirc accepted mapped network drives that trace back to your own hard drive right?
i did $findfile(w:\gcapture\gunz*,0)
invalad parameters:$findfile


and another thing... it didnt return null
it returned the word... of
...

Last edited by sparkicks; 23/12/05 09:31 PM.
Re: aliases (test for last file name) #138079 23/12/05 11:10 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
The first parameter of findfile is the path, the second is the filenames you want to match (can include wildcars), so change the findfile to:

//echo -a Total: $findfile(w:\gcapture\,gunz*,0)

Will return the total files that start with "gunz" in folder w:\gcapture\

Note that if you don't specify it, $findfile will look into subfolders as well, so it will look in all subfolders of w:\gcapture for matches. If you only want to find the matches of the first level of folders, you need to specify the depth, which is the forth parameter.

//echo -a Total: $findfile(w:\gcapture\,gunz*,0,1)

Will return the total number of files starting with "gunz" in the folder w:\gcapture without looking in subfolders of that folder.


Gone.
Re: aliases (test for last file name) #138080 24/12/05 06:41 AM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
as FiberOptics has said //echo -a Total: $findfile(w:\gcapture\,gunz*,0,1) well likely do

how ever the code you gave was so bugged i felt you needed the spots pointed out
Code:
gunznum {
  set %filenum 002  [color:blue]<-- should be using var %filenum = 002, global vas should only be used if needed between runs of a script[/color] 
  set %keepgoing 1 [color:blue]<-- same as above[/color]
  while (keepgoing == 1 ) { [color:blue]<-- variables need there % sign at the front when refenced ie: %keepgoing[/color] 
    if ("W:\gcapture\gunz $+ %filenum  == $null) { [color:blue]<-- need to use IF (!$isfile(W:\gcapture\gunz $+ %filenum))[/color] 
      set %returnv $calc(%keepgoing - 1) [color:blue]<--%keepgoing is always equals 1 so this is always going to result with 0, I assume your ment to be using %filenum[/color] 
      return returnv [color:blue]<-- var returnv needs the % added to it[/color] 
      break [color:blue]<-- well never occur RETURN (above) exits script[/color] 
      set %keepgoing 0[color:blue]<-- well never occur RETURN (above) exits script[/color] 
    }
    else {
      inc filenum  [color:blue]<-- var filenum needs the % added to it, also 002 well result in 3, so a following command of VAR %filenum = $right(00 $+ %filenum,3) [/color] 
    }
  }
}


heres a code rewrite using your code
[code]
gunznum {
var %filenum = 002
var %keepgoing = 1
while (keepgoing == 1) {
if (!$isfile(W:\gcapture\gunz $+ %filenum)) {
var %returnv = $calc(%filenum - 1)
return %returnv
}
else {
inc %filenum | if (%filenum == 1000) { return 999 }
var %filenum = $right(00 $+ %filenum,3)
}
}
}
[code]
* code untested *

Added a protection from endless loop with the checking if moving beyond file 999

Re: aliases (test for last file name) #138081 24/12/05 05:17 PM
Joined: Nov 2005
Posts: 11
S
sparkicks Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: Nov 2005
Posts: 11
yea the amount of bugs i normally have in my programs does amaze me usually i normally just write it down very fast to just get the bones of how im going to do it but it doesnt work i get 0 files each time...

find file works fine but i want to get the aliases working and see what i did wrong...the reason im using the language is to learn how to use it...
btw i take it i just use $gunznum where i want that number to appear right?

Last edited by sparkicks; 24/12/05 05:22 PM.
Re: aliases (test for last file name) #138082 24/12/05 11:33 PM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
correct