mIRC Home    About    Download    Register    News    Help

Print Thread
#268475 21/02/21 11:13 AM
Joined: Dec 2019
Posts: 45
Q
quartz Offline OP
Ameglian cow
OP Offline
Ameglian cow
Q
Joined: Dec 2019
Posts: 45
$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.
Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
See $findfile


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
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

Joined: Dec 2019
Posts: 45
Q
quartz Offline OP
Ameglian cow
OP Offline
Ameglian cow
Q
Joined: Dec 2019
Posts: 45
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.
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
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.

Joined: Dec 2019
Posts: 45
Q
quartz Offline OP
Ameglian cow
OP Offline
Ameglian cow
Q
Joined: Dec 2019
Posts: 45
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


Link Copied to Clipboard