I am using the Directory.GetFi les class and am having
problems with the overloaded version. I want to search
files. I can use the following and it works fine:
Directory.GetFi les(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? 1 5636
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.GetFi les("c:\", "c*")
Console.WriteLi ne("The number of files starting with c is {0}.",
dirs.Length)
Dim dir As String
For Each dir In dirs
Console.WriteLi ne(dir)
Next
Catch e As Exception
Console.WriteLi ne("The process failed: {0}", e.ToString())
End Try
End Sub
End Class
"brian" <bs******@lbrsp ec.com> wrote in message
news:1d******** *************** *****@phx.gbl.. . I am using the Directory.GetFi les class and am having problems with the overloaded version. I want to search files. I can use the following and it works fine:
Directory.GetFi les(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? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 another way to enumerate files and subdirectories recursively which
doesn't take too much memory in CS?
|
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 does not work nor does something like this:
string files = Directory.GetFiles(sDir, "*.doc, *.dot");
|
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 Directory.GetFileSystemEntries(path), but I would
like to know how to put this together, knowing which entry is a Subdirectory
and which entry is a file, and make a recursive list of the Directory
structure below a specific path - - -
|
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
Directory.GetFiles("C:\TSA\DOWNLOADS\TRX\PERFORMANCE_DATA\DOWNLOAD\",
"*1.TXT")
Debug.WriteLine(filename)
Next
|
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. Any sugestions?
Thanks,
Michael.
| |
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 Directory.GetDirectories("C:\\")) {
foreach (string f in Directory.GetFiles(d, "*.exe")) {
MessageBox.Show(f);
}
}
|
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 app, but
I get an access error message when the code is running on a asp.net app.
First I thought it was just a matter of credentials, so I started to use
windows authentication and impersonate the current user, but I still got the
same message.
|
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 it process all files within
subdirectories as well?
Thanks --
Alex
|
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 can copy, etc the file using the
Windows XP explorer.
I can trap the error, but then this traps the entire GetFiles() function,
not just the one bad file.
Is there a way to just trap for the one bad file and continue on?
|
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, "GL*.*");
strFiles.CopyTo(Directory.GetFiles(SemaSettings.InputFilePath,
"IN.*"),strFiles.Length-1);
strFiles.CopyTo(Directory.GetFiles(SemaSettings.InputFilePath,
"TX.*"),strFiles.Length-1,);
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |