This is the code snippet used to get the files/folder present in a particular folder/sub directories.
Get Files and Folders From a Directory
using System.IO;
using System;
namespace folder_information
{
public partial class folder
{
//Function to get all the folders present in that particular location,Use
string[] folders = Directory.GetDirectories(@"C:\myfolder\Projects");
//Function to get all the files present in that particular location,Use
string[] files = Directory.GetFiles(@"C:\myfolder\Projects");
//Function to get all the files present in that particular location with particular extension,Use
string[] cs_files= Directory.GetFiles(@"C:\myfolder\Projects","*.cs");
//Function to get all the files present in that particular location and its subfolders with particular extension,Use
string[] cs_files= Directory.GetFiles(@"C:\myfolder\Projects","*.cs",SearchOption.AllDirectories);[/CODE]
}
}
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.