mIRC Homepage
Posted By: Adrenalin $Disk addition .. - 29/05/03 05:27 PM
Get the disk's number .. Like $disk(0) - must return number of the disk's ..
Posted By: qwerty Re: $Disk addition .. - 30/05/03 02:20 AM
Until it gets implemented, check out this alias:
Code:
[color:green]; Usage: $diskn(N,type).prop
; Returns the Nth drive letter of the specified type.
; The <type> parameter is optional, if it is omitted,
; all existing disks are taken into account.
; If N is 0 (or non-numeric) it returns the
; total number of disks (of the specified type, if 
; the <type> parameter is present)
; prop can be whichever property is supported by
; mIRC's $disk()
; Examples: 
; $disk(0) -> returns the total number of drives
; $disk(3) -> returns the letter of the 3rd drive
; $disk(0,fixed) -> returns the total number of hard disk drives
; $disk(1,fixed) -> returns the letter of the 1st hard disk drive (normally C)
; $disk(2,cdrom).label -> returns the volume label of the 2nd CD-ROM drive[/color]
alias diskn {
  if * !iswm $1 { return }
  if !%drives { makedriveslist }
  if $1 !isnum 1- { return $wildtok(%drives,$+(*:,$2,*),0,32) }
  if $istok(type free label size unc,$prop,32) { return $disk($gettok($wildtok(%drives,$+(*:,$2,*),$1,32),1,58)). [ $+ [ $prop ] ] }
  return $gettok($wildtok(%drives,$+(*:,$2,*),$1,32),1,58)
}

[color:green]; The following alias caches the drives info in a global 
; variable named %drives, so that the $diskn() alias doesn't 
; have to retrieve it every time.
; $diskn() re-retrieves the drives information if
; the %drives variable isn't found; so to clear the
; cached info and force an update just unset %drives
; A perhaps good idea is to call /makedriveslist
; during mIRC startup, with something like:
; on *:start: makedriveslist[/color]
alias makedriveslist {
  unset %drives
  var %i = 65
  while %i < 91 {
    if $disk($chr(%i)).type { 
      %drives = %drives $+($chr(%i),:,$ifmatch)
    }
    inc %i
  }
}

Posted By: Raccoon Re: $Disk addition .. - 30/05/03 03:50 AM
Is if * !iswm $1 { return } really faster than
if !$1 { return }?
Posted By: qwerty Re: $Disk addition .. - 30/05/03 04:22 AM
No, it's just different :tongue: You probably know that if !$1 means "if $1 is $null OR $false OR 0". In $diskn(), 0 is an acceptable value (returning the total number of drives), $null is not. So I need something like if $1 != $null. This one is slightly slower than if * !iswm $1. I would assume that the difference isn't noticeable in the vast majority of scripts but I always tend to use the faster alternative, unless there are other more important reasons to do otherwise.
Posted By: Raccoon Re: $Disk addition .. - 30/05/03 06:07 AM
Ah, i see.
I suppose there's always (!$0) but your method is just as good. It just struck me as an interesting habitual way of checking for valid parameters.
Posted By: Adrenalin Re: $Disk addition .. - 30/05/03 11:23 AM
Thank you smile
Posted By: qwerty Re: $Disk addition .. - 30/05/03 11:36 AM
Yeah, there's if !$0, but there is a subtle difference for custom identifiers: in a call like $diskn($null), $0 returns 1, although the 1st parameter is $null.
© mIRC Discussion Forums