FSO: Using regexps?

K

Ken Fine

I'd like my FSO script to act only on files that fit a pattern, files that
include "icon" in the name.
Below, I have FSO code that acts on files that begin with "icon" and have an
extension of .jpg.

I'd prefer it if the script would act in instances where "icon" appeared
anywhere in the filename.

Any help out there?

Thanks...


Dim fso, f, f1, fc, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folder)
Set fc = f.Files
For Each f1 in fc
if fso.GetExtensionName(f1) = "jpg" and left(f1.name,4) = "icon" Then
%> <img
src=http://whatever.whatever.com/path/<%Response.Write(f1.name)%>><br> <%
end if
Next
%>
 
G

Guest

Good advice, thanks Curt. For anyone who needs exact syntax, here's how you
do it:

if fso.GetExtensionName(f1) = "jpg" and instr(1,f1,"icon",1) > 0 Then

I should give this a go with the Regexp method just as a learning thing.

-KF
 
C

Curt_C [MVP]

RegEx is a powerfull thing, I've just never learned it well so I tend to not
use it :}

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
 
S

swp

Ken Fine said:
I'd like my FSO script to act only on files that fit a pattern, files that
include "icon" in the name.
Below, I have FSO code that acts on files that begin with "icon" and have an
extension of .jpg.

I'd prefer it if the script would act in instances where "icon" appeared
anywhere in the filename.

Any help out there?

Thanks...


Dim fso, f, f1, fc, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folder)
Set fc = f.Files
For Each f1 in fc
if fso.GetExtensionName(f1) = "jpg" and left(f1.name,4) = "icon" Then
%> <img
src=http://whatever.whatever.com/path/<%Response.Write(f1.name)%>><br> <%
end if
Next
%>

the only part you need to change is:
left(f1.name,4) = "icon"

use something like:
instr(lcase(f1.name), "icon")
instead, which returns zero (aka false) if "icon" is not found within
the lowercase string f1.name.

syntax and typos go hand in hand, please don't blame me for either

swp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top