473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Get a collection of files whose names match a regular expression?

Hi All

Is it possible with the Microsoft Scripting Runtime library to get a
collection of all the files in a folder that match a regular
expression?

That is, can I make a call through the FileSystemObject or a Folder
object to get just the files that start with the letter 'A' for
example?

The only API I can see is Folder.Files which gives *all* the files
then I would have to sort through and do the pattern matching myself
which seems like it will be very slow. Any ideas?

Thanks in advance,
Chrisso
Jul 24 '08 #1
7 2404
On Jul 24, 7:05*am, Chrisso <chris75sut...@gmail.comwrote:
Hi All

Is it possible with the Microsoft Scripting Runtime library to get a
collection of all the files in a folder that match a regular
expression?

That is, *can I make a call through the FileSystemObject or a Folder
object to get just the files that start with the letter 'A' for
example?

The only API I can see is Folder.Files which gives *all* the files
then I would have to sort through and do the pattern matching myself
which seems like it will be very slow. Any ideas?

Thanks in advance,
Chrisso
You can use System.IO.Directory.GetFiles to do a much better search
(with wildcards), however if you wanted to do a Regex search you'd
have to loop through the files and do a Regex.IsMatch on each file,
which would be very, very slow. Your other option, which wouldn't
truly be Regex, would be to create a LINQ query that represented the
Regex pattern and use it. LINQ should be much faster than using
Regex.IsMatch.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
Jul 24 '08 #2
Thanks Seth

I will try out System.IO.Directory.GetFiles as wildcard matching is
fine.

I am actually wrting my VB code in Excel VBA - do I need to include a
reference to access this functionality?

Chrsso

Jul 24 '08 #3
See the Dir function then. It doesn't use regular expression but support the
* and ? wildcards. Is this enough ?

An Excel programming group would be better....

--
Patrice

"Chrisso" <ch***********@gmail.coma écrit dans le message de groupe de
discussion :
27**********************************...oglegroups.com...
Thanks Seth

I will try out System.IO.Directory.GetFiles as wildcard matching is
fine.

I am actually wrting my VB code in Excel VBA - do I need to include a
reference to access this functionality?

Chrsso
Jul 24 '08 #4
On Jul 24, 7:25*am, Chrisso <chris75sut...@gmail.comwrote:
Thanks Seth

I will try out System.IO.Directory.GetFiles as wildcard matching is
fine.

I am actually wrting my VB code in Excel VBA - do I need to include a
reference to access this functionality?

Chrsso
Wow, I completely missed that you weren't using .NET. Now that I see
you aren't, I have to send you to the excel programming group since we
can't be of help to you here (Excel VBA is in no way VB.NET)

http://groups.google.com/group/micro...ing/topics?lnk

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
Jul 24 '08 #5
Thankyou. I will give it a whirl.

I posted here as I thought the topic was independent of Excel. MS is
weird.

Chrisso
Jul 24 '08 #6
On Jul 24, 7:49*am, Chrisso <chris75sut...@gmail.comwrote:
Thankyou. I will give it a whirl.

I posted here as I thought the topic was independent of Excel. MS is
weird.

Chrisso
The topic is independent of Excel, but it's not from VBA. Let me
rephrase my earlier statement:

VBA is in no way Visual Basic .NET

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
Jul 24 '08 #7
I would ask VBA questions in the vb6 group vba is 99.9% vb6

"Chrisso" wrote:
Hi All

Is it possible with the Microsoft Scripting Runtime library to get a
collection of all the files in a folder that match a regular
expression?

That is, can I make a call through the FileSystemObject or a Folder
object to get just the files that start with the letter 'A' for
example?

The only API I can see is Folder.Files which gives *all* the files
then I would have to sort through and do the pattern matching myself
which seems like it will be very slow. Any ideas?

Thanks in advance,
Chrisso
Jul 25 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Ron Adam | last post by:
Is it possible to match a string to regular expression pattern instead of the other way around? For example, instead of finding a match within a string, I want to find out, (pass or fail), if...
0
by: Follower | last post by:
Hi, I am working on a function to return extracts from a text document with a specific phrase highlighted (i.e. display the context of the matched phrase). The requirements are: * Match...
1
by: Venkat | last post by:
Hi, I am using match function of string to find if a character is there in a string. The function Match is working fine with all the other characters except when the searching character is "+"....
2
by: Christian Staffe | last post by:
Hi, I would like to check for a partial match between an input string and a regular expression using the Regex class in .NET. By partial match, I mean that the input string could not yet be...
1
by: Prem | last post by:
Hi, I need to search a particular directory for all the files that do not have any extension and have a specific naming convension. The first 3 characters of the file name are alpha and the rest...
38
by: Steve Kirsch | last post by:
I need a simple function that can match the number of beginning and ending parenthesis in an expression. Here's a sample expression: ( ( "john" ) and ( "jane" ) and ( "joe" ) ) Does .NET have...
2
by: Edward Diener | last post by:
In C++ an overridden virtual function in a derived class must have the exact same signature of the function which is overridden in the base class, except for the return type which may return a...
5
by: ari | last post by:
hey all, is there a way to search an entire text file for a string and if it finds it, read the entire line it was found on? thanks, ari
14
by: Andy B | last post by:
I need to create a regular expression that will match a 5 digit number, a space and then anything up to but not including the next closing html tag. Here is an example: <startTag>55555 any...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.