This script uses COMs to search for files, while keeping mIRC from freezing. What's interesting about this is it can be used directly in a script(No need for a callback alias or a signal) IE:
alias test {
echo -a This will echo when listfiles is completed but you won't notice mIRC has frozen! $listfiles($Mircdir,mirc.exe,b,&test)
}
To Use:
$listfiles( Directory , Matchtext , Switches , Ignore Matchtext , @Win|file|&bvar|dialog ID )
Directory: (Required)
The directory in which you would like to search
You can specified multiple directories by seperating them with a semicolon(;)
Ex: C:\;D:\ would search in "C:\" and "D:\" for matching files
If you wish to search all drives connected to your computer, you can simply specify \, /, "\", or "/". This will return an error if you try to specify more than one directory
Matchtext: (Required)
This is a wildcard pattern for the files you wish to find.
You can include multiple wildcard matchtexts by seperating them with a semicolon(;)
Ex: this;that would match any file with "this" or "that" in it's name
If you specify the r switch, then the matchtext will be seen as a regex matching pattern. You are limited to the //i matching switch.
Switches: (Optional)
r - File matchtext is a regex pattern
p - Matchtext should match whole file path instead of just filename
R - File ignore matchtext is a regex pattern
P - Ignore matchtext should match whole file path instead of just filename
S - This parses the files found as though passed through $ShortFn()
dN - This specifies the depth of subfolders to search. if N is zero only the root folder is searched.
f - This switch indicates a file is the output.
s - This switch indicates that the active connection's status window is the output.
b - This switch indicates a &bvar has been specified as the output. The files will be divided in the &bvar by $!crlf.
wN - This switch indicates an @window has been specified as the output. If N is zero or not present the window buffer will be filled. If N is 1 then the output is the window's side listbox.
D - This signifies a dialog id is the output
o - This switch clears the output @Window or file before adding matched files to it. If this switch isn't specified, it will append any matches to the specified output
Ignore Matchtext: (Optional)
This is a wildcard pattern for the files you wish to ignore if they match the pattern specified.
You can exclude multiple wildcard matchtexts by seperating them with a semicolon(;)
Ex: this;that would ignore any file with "this" or "that" in it's name.
If you specify the R switch, then the ignore matchtext will be seen as a regex matching pattern. You are limited to the //i matching switch.
@Win|file|&bvar|dialog id: (Required unless the s switch is specified)
This is the window, file or bvar inwhich the found files will be listed in.
If this is a file then any matches will be appended to the file unless the o switch is specified inwhich case the file will be overwritten
I've tested it as much as I can. If you find a bug please contact me and I will fix it as soon as I can :)
On *:Load:{
if ($version < 6.35) {
echo -ac info * $!ListFiles() $LFS:ver $+ : Your version of mIRC is too old, please upgrade to atleast 6.35
.unload -rs $script
}
elseif ($os isin 9598) {
echo -ac info * $!ListFiles() $LFS:ver $+ : You windows version is too old to support this script. You need atleast windows 2000 or later.
.unload -rs $script
}
else {
echo -ac info2 * $!ListFiles() $LFS:ver is now loaded.
ListFiles:help
}
}
alias ListFiles {
if (!$isid) return
var %dir, %mTx, %iTx, %fTx, %com, %fle, %dph, %a, %o = $($ $+ $0,2)
if ($calc($count($1,") % 2)) LFS:Cleanup -e 0 Invalid directory: Mixmatched quotation(") marks.
elseif (!$regex(Dir,$1,/\G(?|"([^"\x2C;]+)"|([^\x2C;"]+))(?:;|$)/g)) LFS:Cleanup -e 0 Invalid directory list specified.
else {
var %x = 1, %n = $regml(dir,0), %d, %dir
while (%x <= %n) {
%d = $regml(dir,%x)
if (%d == / || %d == \) {
if (%n != 1) LFS:Cleanup -e 0 Invalid directory list: Cannot specify another directory when "/" is specified.
else {
%dir = /
break
}
}
if (!$isdir(%d)) LFS:Cleanup -e 0 Invalid directory list: Unable to locate $qt(%d)
%dir = $addtok(%dir,$iif(: !isin %d && $isdir($mircdir $+ %d),$mircdir) $+ $regsubex(%d,[\\\/]+$,),1)
inc %x
}
}
if ($0 < 2) LFS:Cleanup -e 0 Too few parameters specified
elseif ($0 > 5) LFS:Cleanup -e 0 Too many parameters specified
elseif ($2 == $null) LFS:Cleanup -e 0 No match text or pattern specified specified.
elseif ($3 == $null) LFS:Cleanup -e 0 No output switch specified
elseif (!$regex($3,^(?:(?|([rRSopP])|(d)\d+|(?:([sbfD])|(w)[01]?)(?!.*[sbDfw]))(?!.*\1))*$)) { LFS:Cleanup -e 0 Invalid switch combination specified. }
elseif (r !isincs $3 && $LFS:ToRegex($2) == $Null) { LFS:Cleanup -e 0 Invalid matchtext specified }
elseif (r isincs $3 && $LFS:RegChck($2) == $null) { LFS:Cleanup -e 0 Invalid Match pattern specified }
elseif (s isincs $3 && $0 == 5) { LFS:Cleanup -e 0 Output specified with the s switch }
elseif (w isincs $3) && ($window(%o).type !isin custom picture || ($v1 == picture && w1 !isincs $3)) { FSS:Cleanup -e 0 Invalid window specified. }
elseif (w1 isincs $3) && ($line(%o,0,1).state = $null) { LFS:Cleanup -e 0 Specified window does not have a side listbox }
elseif (b isincs $3 && &* !iswm %o) { LFS:Cleanup -e 0 Invalid Binary variable specified }
elseif (f isincs $3 && !$regex($nopath($noqt(%o)),^[^\x2C<>:"\\\/|?*]*\.[<>:"\\//|?*.]+$)) { LFS:Cleanup -e 0 Invalid filename specified }
elseif (D isincs $3) && ($numtok(%o,32) != 2 || !$dialog($gettok(%o,1,32)) || $gettok(%o,2-,32) $+ . !isnum 1- || !$did($gettok(%o,1,32),$gettok(%O,2,32)).isid) { LFS:Cleanup -e 0 Invalid dialog or dialog ID specified. }
elseif (R isincs $3) && ((s !isincs $3 && $0 != 5) || (s isincs $3 && $0 != 4)) { LFS:Cleanup -e 0 No ignore text specified }
elseif (R isincs $3) && ($LFS:RegChck($4) == $Null) { LFS:CleanUp -e 0 Invalid Ignore match pattern: $v1 }
%mTx = $iif(r isincs $3,$LFS:RegChck($2),$LFS:ToRegex($2))
%iTx = $iif((s isincs $3 && $0 == 4) || $0 == 5,$iif(R isincs $3,$LFS:RegChck($4),$LFS:ToRegex($4)))
%com = $ticks | while ($com(ListFiles- $+ %com)) inc %com
%com = ListFiles- $+ %com
%fle = $iif(f isincs $3,$iif(: !isin %o,$scriptdir) $+ $noqt(%o),$scriptdir $+ %com $+ .tmp)
%dph = $iif($regex($3,d0*(\d+)),$regml(1),-1)
%fTx = (mReg.Test(File $+ $iif(p !isincs $3,.Name) $+ ))
if (%fTx) %txt = %txt and (not iReg.Test(File $+ $iif(P !isincs $3,.Name) $+ ))
%a = aline $+(@,%com)
window -hn $+(@,%com)
%a on error resume next
%a Set FSO = CreateObject("Scripting.FileSystemObject")
%a Set F = FSO. $+ $iif(o isin $3 || !$isfile(%fle),CreateTextFile,OpenTextFile) $+ (" $+ %fle $+ ")
%a maxdepth = %dph
%a depth = 0
%a Set mReg = New RegExp
%a mReg.Global = True
%a mReg.Pattern = $qt($gettok(%mTx,2-,32))
%a mReg.IgnoreCase = $iif($gettok(%mTx,1,32),true,false)
if (%iTx) {
%a Set iReg = new RegExp
%a iReg.Global = True
%a iReg.Pattern = $qt($gettok(%iTx,2-,32))
%a iReg.IgnoreCase = $iif($gettok(%iTx,1,32),true,false)
}
if (%dir == /) %a For Each Drive In FSO.Drives : If Drive.IsReady Then Call FindFile(Drive) : Next
else %a For Each Path in Array(" $+ $replace(%dir,$chr(1)," $+ $chr(44) $+ ") $+ ") : Call FindFile(Path & "\") : Next
%a Sub FindFile(ThisFolder)
%a For Each File In FSO.GetFolder(ThisFolder).Files
%a if (File <> $qt($scriptdir $+ %com $+ .vbs) and file <> $qt($scriptdir $+ %com $+ .tmp) $+ $chr(41) and %fTx then F.WriteLine(File $+ $iif(S isincs $3,.ShortPath) $+ )
%a Next
%a if (maxdepth <> -1 and maxdepth <= depth) then exit sub
%a depth = depth + 1
%a For Each Folder In FSO.GetFolder(ThisFolder).SubFolders
%a a = folder.Attributes
%a if (a >= 2048) then a = a - 2048
%a if (a >= 1024) then a = a - 1024
%a if (a >= 512) then a = a - 512
%a if (a >= 256) then a = a - 256
%a if (a >= 128) then a = a - 128
%a if (a >= 64) then a = a - 64
%a if (a >= 32) then a = a - 32
%a if (a >= 16) then a = a - 16
%a if (a < 4) then Call FindFile(Folder)
%a Next
%a depth = depth -1
%a End Sub
%a F.Close
savebuf $+(@,%com) $qt($scriptdir $+ %com $+ .vbs)
close -@ $+(@,%com)
%a = $iif(o !isincs $3 && $lines(%file),$v1,0)
.comopen %com WScript.Shell
if (!$com(%com,run,1,bstr*,$qt($scriptdir $+ %com $+ .vbs),uint,0,bool,true) || $comerr) { LFS:Cleanup -e %com Unable to start finding files. }
.comclose %com
if (!$isfile(%fle)) LFS:Cleanup -e %com Unable to complete finding of files.
%a = $calc($lines(%fle) - %a)
if (s isincs $3) loadbuf -s $+ $iif(o isincs $3,r) $qt(%fle)
elseif (w1 isincs $3) loadbuf -l $+ $iif(o isincs $3,r) %o $qt(%fle)
elseif (w isincs $3) loadbuf $iif(o isincs $3,-r) %o $qt(%fle)
elseif (D isincs $3) loadbuf $iif(o isincs $3,-ro,-o) %o $qt(%fle)
elseif (b isincs $3) bread $qt(%file) 0 $file(%file)
return $LFS:Cleanup(%com,%a)
:error
LFS:Cleanup -e %com Error: $error
reseterror
halt
}
alias -l LFS:Ver return v2.31b
alias -l LFS:RegChck {
if ($regex($1,^(?|m(.)|(\/))(.*)\1(i?)$)) return $iif($regml(3),i,0) $regml(2)
if ($regex($1-,^(?!(?:\/|m.)).)) return 0 $1-
}
alias -l LFS:ToRegex {
if ($regex($1,[\\\/:"<>|])) { return }
tokenize 59 $1-
var %x = 1, %c, %r, %p
while (%x <= $0) {
%c = $(,$ $+ %x)
if (!$len(%c)) return
%p = $regsubex(%c,/([\Q$^|[]{}()\/.+\E]+)|(&(?= |$))|([?*]+)/g,$LFS:ToRegx2(\t))
if (%x = 1) %r = %p
elseif (%x == 2) %r = (?: $+ %r $+ )|(?: $+ %p $+ )
else %r = %r $+ |(?: $+ %p $+ $chr(41)
inc %x
}
return i "^(?: $+ %r $+ )$"
}
alias -l LFS:ToRegx2 {
if ($1 == &) return \S+\b
if (* !isin $1 && ? !isin $1) return \ $+ $iif($len($1) > 2,Q $+ $1 $+ \E,$mid($1,1,1) $+ $iif($mid($1,2,1),\ $+ $v1))
if (? !isin $1) return .*
if ($count($1,?) < 5) return $str(.,$v1) $+ $iif(* isin $1,+)
return $+(.,$chr(123),$count($1,?),$iif(* isin $1,$chr(44)),$chr(125))
}
alias -l LFS:CleanUp {
var %err, %com, %msg
if ($1 == -e) var %err = 1, %com = $iif($2,$2),%msg = $3-
else var %com = $1, %msg = $2
if (%com) {
if ($com(%com)) .comclose %com
if ($window(@ $+ %com)) close -@ $v1
if ($isfile($scriptdir $+ %com $+ .tmp)) .remove $qt($scriptdir $+ %com $+ .tmp)
if ($isfile($scriptdir $+ %com $+ .vbs)) .remove $qt($scriptdir $+ %com $+ .vbs)
}
if (!%err) return %msg
echo -ac info * $!FindFileX: %msg
halt
}
alias ListFiles:Help {
%a = echo -a
%a $!04ListFiles( 12Directory , 12Matchtext , 12dNpPrRSosfbwND , 12[ignore matchtext] , 12[file|&bvar|@win|dialog id])
%a Searches for specified files in specified directories, outputs them to the status
%a window|file|&bvar|@win|dialog id and then returns the number of files found all without freezing mIRC
%a while searching for files.
%a
%a 12Directory:
%a This is the directory to be searched. You can specify multiple directories by seperating them with
%a a semicolon(;), or you can specify you entire computer by specifying "/" (This will throw an error
%a if you try to specify "/" with another directory)
%a
%a 12Matchtext:
%a The wildcard pattern inwhich you would like to match files with. You can specify multiple wildcard
%a patterns by seperating them with a semicolon(;)
%a You can specify the "12r" switch to match as a regular expression instead of a wildcard match and/or
%a the "12p" switch to match the whole filepath instead of just the filename
%a
%a 12Switches:
%a
%a These switches control the behavior of finding files and can be grouped together
%a 12dN - Specifies the max depth that can be searched(12N Must be an integer of atleast zero). if 12N is
%a zero subdirectories will NOT be searched
%a 12p - Matchtext is to match the whole path\filename instead of just the filename
%a 12r - Matchtext is a Regular Expression
%a 12P - Ignore MatchText is to match the whole path\filename instead of just the filename
%a 12R - Ignore Matchtext is a Regular Expression
%a 12S - Results will be returned as though passed through $ShortFN()
%a 12o - Clear the output before adding the found results.
%a
%a These switches control the output of the found files.(These cannot be grouped together)
%a 12s - Signifies the active status window will be the output window
%a 12f - Signifies a file has been specified as the output.(Each matching file will be placed on a
%a new line)
%a 12b - Signifies a binary variable has been specified as the output.(Matching files will be
%a sepereated by $crlf)
%a 12w - Signifies an @win is the specified output.
%a 12w1 - This signifies an @win's side listbox is the specified output. w1(one)
%a 12D - signifies a dialog's ID has been specified as the output.
%a
%a 12Ignore Matchtext: (Optional)
%a The wildcard pattern to ignore files which match the specified matchtext. You can specify multiple
%a wildcard patterns by seperating them with a semicolon(;)
%a You can specify the "12R" switch to ignore as a regular expression instead of a wildcard match and/or
%a the "12P" switch to match check the whole filepath instead of just the filename
%a
%a 12File|&bvar|@win|dialog id: (required unless the "12s" switch is specified)
%a This is the file|&bvar|@win|dialog ID you wish to output matching files to.
%a
%a 03To see this message again at any time, simply type: /ListFiles:Help
}