Back in my VB6 programming days I could use a function call dir("enter in file path or directory"). This worked out nice if I wanted to see if any files existed in a folder that contained a part of a string, for example(sFile = dir(sDir & "1.*")). If not files existed I would not have to loop through the entire folder, I cannot find something similar to this in C#. It seems like I have to loop through the folder and look at use the 'StartsWith' function or look at the left couple of characters in the file name. Is there a C# equivelant to what I am looking for?
thanks...
Loading
AlexPosted Aug 15, 2008, 6:33 PM
FileInfo[] files = info.GetFiles("*win*"); //will return an array of files with the letters "win" in the name
foreach (FileInfo f in files)
{
Console.WriteLine(f.Name);
}
Make sure to add the System.IO namespace.
AlanPosted Aug 15, 2008, 6:26 PM
Check out this overload of the static System.IO.Directory.GetFiles() method which can take a wildcard in the search pattern:
http://msdn.microsoft.com/en-us/library/wz42302f.aspx
You can then check the length of the resulting string array to see whether there are any matching files.