mIRC Home    About    Download    Register    News    Help

Print Thread
$exists with wildcards #268475 21/02/21 11:13 AM
Joined: Dec 2019
Posts: 42
Q
quartz Offline OP
Ameglian cow
OP Offline
Ameglian cow
Q
Joined: Dec 2019
Posts: 42
$exists(C:\path\path2\subfolder\subfolder2\filename.ext)

returns $true


$exists(C:\path\path2\subfolder\subfolder2\filename*.ext)

(eg, if it's "filename2 someinfo.ext")

returns $false

Last edited by quartz; 21/02/21 12:49 PM.
Re: $exists with wildcards [Re: quartz] #268476 21/02/21 12:43 PM
Joined: Jul 2006
Posts: 3,741
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,741
See $findfile


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: $exists with wildcards [Re: quartz] #268479 21/02/21 05:17 PM
Joined: Jan 2004
Posts: 1,510
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,510
Also, you shouldn't be using $exists to check for a non-wildcard, because that matches files *and* folders. For that you should use $isfile. i.e. this returns $true even though it's not a file:

//echo -a $exists(c:\windows\) is true
//echo -a $isfile(c:\windows\) is false

Re: $exists with wildcards [Re: maroon] #268484 21/02/21 08:24 PM
Joined: Dec 2019
Posts: 42
Q
quartz Offline OP
Ameglian cow
OP Offline
Ameglian cow
Q
Joined: Dec 2019
Posts: 42
ok.. so I don't know if anyone can advise

I have, eg "filename4 someinfo.ext"

now I want to flag up if the 4 is part of the filename, or if the 4 is a number I've added afterwards.

if the 4 is -not- part of the filename (if the 4 is a number I've added), it makes sense that either "filename2 someinfo.ext" or "filename 2 someinfo.ext" would exist, (depending on how I saved it previously, with the 2 tucked up with the name or seperate")

if the 4 is part of the filename, then the second file would be "filename42 someinfo.ext", or "filename4 2 someinfo.ext"

so I want to find out if "filename2*", or "filename 2*" exists (note the stars)

but the $exists ident doesn't work for the wildcard. would $findfile work in the above? or am I just getting too wrapped up in it lol.

Last edited by quartz; 21/02/21 08:39 PM.
Re: $exists with wildcards [Re: quartz] #268485 21/02/21 09:03 PM
Joined: Jan 2004
Posts: 1,510
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,510
Code
//write -c "filename2 foo.txt" abc | write -c "filename 2bar.txt" def | echo -a $findfile($mircdir,filename2 *,1,1) and $findfile($mircdir,filename 2*,1,1)



For each pair of 1,1's, the 2nd is the folder depth to search, 1 = doesn't search subfolders
the 1st of the pair returns the Nth matching filename, and changing to 0 returns the total count of matches. If you just want to see if a matching file exists, it's faster to see if the 1st match is $null, rather than waste time finding potentially hundreds of matches.

This method won't be able to discern if the X in "filename4X text.txt" is a number or something else, so if your file naming scheme is chosen poorly you'd need to fetch the result to a variable then do a regex test against that.

Re: $exists with wildcards [Re: maroon] #268491 22/02/21 08:30 PM
Joined: Dec 2019
Posts: 42
Q
quartz Offline OP
Ameglian cow
OP Offline
Ameglian cow
Q
Joined: Dec 2019
Posts: 42
ah cool. yeah I was putting too many $exists in

(btw) ......"filename info.txt" doesn't work for $findfile, you don't need the " " for a file (even) with a space in it