mIRC Homepage

$exists with wildcards

Posted By: quartz

$exists with wildcards - 21/02/21 11:13 AM

$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
Posted By: Wims

Re: $exists with wildcards - 21/02/21 12:43 PM

See $findfile
Posted By: maroon

Re: $exists with wildcards - 21/02/21 05:17 PM

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
Posted By: quartz

Re: $exists with wildcards - 21/02/21 08:24 PM

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.
Posted By: maroon

Re: $exists with wildcards - 21/02/21 09:03 PM

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.
Posted By: quartz

Re: $exists with wildcards - 22/02/21 08:30 PM

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
© 2021 mIRC Discussion Forums