C# Directory EnumerateFileSystemEntries(String, String)
Description
Directory EnumerateFileSystemEntries(String, String)
Returns
an enumerable collection of file-system entries that match a search pattern
in a specified path.
Syntax
Directory.EnumerateFileSystemEntries(String, String)
has the following syntax.
public static IEnumerable<string> EnumerateFileSystemEntries(
string path,
string searchPattern
)
Parameters
Directory.EnumerateFileSystemEntries(String, String)
has the following parameters.
path
- The directory to search.searchPattern
- The search string to match against the file-system entries in path.
Returns
Directory.EnumerateFileSystemEntries(String, String)
method returns <
Example
Returns an enumerable collection of file-system entries that match a search pattern in a specified path.
/*from w w w .ja v a 2 s . c om*/
using System;
using System.IO;
class Program
{
static void Main(string[] args)
{
string sourceDirectory = @"C:\current";
string archiveDirectory = @"C:\archive";
var da = Directory.EnumerateFileSystemEntries(sourceDirectory,"*");
foreach (string currentFile in da)
{
string fileName = currentFile.Substring(sourceDirectory.Length + 1);
Directory.Move(currentFile, Path.Combine(archiveDirectory, fileName));
}
}
}