473,396 Members | 1,995 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,396 software developers and data experts.

Directory.GetFiles

I am using the Directory.GetFiles class and am having
problems with the overloaded version. I want to search
files. I can use the following and it works fine:

Directory.GetFiles(Path, k)
Path: c:/Test/
k: 3

It will query all files in the test directory with a file
that is named 3.

I need to add the wildcard behind it to get me all the
files in the test directory that begins with 3. If I
hardcode "3*" it works fine. But 'k' will be changing
all the time so I need a variable of string data type.

I have tried:
(Path, k*)
(Path, "k*")
(Path, k"*")
None of them work. I either get no files or blue
squigglies in other parts of my code.

Any ideas? Can you wildcard search with a paramater?
Nov 20 '05 #1
1 5620
This is straight from the docs...

So with your k variable do this

(Path, k & "*")

and it will evaluate the string before passing the parameter...

And you will be good.

-cJ
Imports System
Imports System.IO

Public Class Test
Public Shared Sub Main()
Try
' Only get files that begin with the letter "c."
Dim dirs As String() = Directory.GetFiles("c:\", "c*")
Console.WriteLine("The number of files starting with c is {0}.",
dirs.Length)
Dim dir As String
For Each dir In dirs
Console.WriteLine(dir)
Next
Catch e As Exception
Console.WriteLine("The process failed: {0}", e.ToString())
End Try
End Sub
End Class

"brian" <bs******@lbrspec.com> wrote in message
news:1d****************************@phx.gbl...
I am using the Directory.GetFiles class and am having
problems with the overloaded version. I want to search
files. I can use the following and it works fine:

Directory.GetFiles(Path, k)
Path: c:/Test/
k: 3

It will query all files in the test directory with a file
that is named 3.

I need to add the wildcard behind it to get me all the
files in the test directory that begins with 3. If I
hardcode "3*" it works fine. But 'k' will be changing
all the time so I need a variable of string data type.

I have tried:
(Path, k*)
(Path, "k*")
(Path, k"*")
None of them work. I either get no files or blue
squigglies in other parts of my code.

Any ideas? Can you wildcard search with a paramater?

Nov 20 '05 #2

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

Similar topics

3
by: S. Han | last post by:
I'm using Directory.GetFiles to enumerate files in a directory. The problem is if you have to enumerate all files + subdirectories recursively, it takes too much memory, and it fails. Is there...
2
by: John Smith | last post by:
Hello all: I am trying to search for more than one extension in a directory at the same time with the following code: string files = Directory.GetFiles(sDir, "*.doc*.dot"); However, this...
4
by: Elmo Watson | last post by:
Is there a way, with the System.IO class, to do a recursive list of a directory structure? For instance, in DirectoryInfo, you have GetDirectories and GetFiles .... In Directory, you have...
2
by: OpticTygre | last post by:
I have a directory of 27 files. The files end in either 1.txt, 2.txt, 3.txt, or 4.txt. If I say: For Each filename As String In...
3
by: Michael | last post by:
Hi, I have been using Directory.GetFiles("g://"); in my c# application. But now my boss want's me to do Directory.GetFiles(IP address); I have been unable to figure out how to get this to work....
3
by: cjb | last post by:
Is there a way to get Directory.GetFiles to return multi-language file names? I haven't found any overloads that allow any such parameter. The way I am using it now is: foreach (string d in...
2
by: =?Utf-8?B?RGFuaWVsIENvcnLDqmE=?= | last post by:
Hi, I've been trying to use Directory.GetFiles() and also DirectoryInfo.GetFiles() to list files on a remote server using "\\server_name\dir_name" like paths. It works fine on a test windows...
2
by: Alex | last post by:
Hello, I'm creating a program to parse a directory and all files within that directory (including subdirectories), but 'directoryinfo' only parses the current directory. Is it possible to have...
3
by: Michael Jackson | last post by:
In my .NET 2.0 VS 2005 VB application, I'm using Directory.GetFiles(path) to get all the files in the directory. However, I'm getting an error regarding "Illegal character in Path", even though I...
0
by: tshad | last post by:
I am trying to do multiple Directory.GetFiles and append the results to one array that I will process. I tried this: string strFiles; strFiles = Directory.GetFiles(SemaSettings.InputFilePath,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.