Call opendir() function to open all file in present directory. Initialize dr pointer as dr = opendir("."). If(dr) while ((en = readdir(dr)) != NULL) print all the file name using en->d_name.
Substitute dir /A:D. /B /S > FolderList. txt to produce a list of all folders and all subfolders of the directory. WARNING: This can take a while if you have a large directory.
using System.IO;
DirectoryInfo d = new DirectoryInfo(@"D:\Test"); //Assuming Test is your Folder
FileInfo[] Files = d.GetFiles("*.txt"); //Getting Text files
string str = "";
foreach(FileInfo file in Files )
{
str = str + ", " + file.Name;
}
Hope this will help...
using System.IO; //add this namespace also
string[] filePaths = Directory.GetFiles(@"c:\Maps\", "*.txt",
SearchOption.TopDirectoryOnly);
It depends on what you want to do.
ref: http://www.csharp-examples.net/get-files-from-directory/
This will bring back ALL the files in the specified directory
string[] fileArray = Directory.GetFiles(@"c:\Dir\");
This will bring back ALL the files in the specified directory with a certain extension
string[] fileArray = Directory.GetFiles(@"c:\Dir\", "*.jpg");
This will bring back ALL the files in the specified directory AS WELL AS all subdirectories with a certain extension
string[] fileArray = Directory.GetFiles(@"c:\Dir\", "*.jpg", SearchOption.AllDirectories);
Hope this helps
Does exactly what you want.
System.IO.Directory.GetFiles
Take a look at Directory.GetFiles Method (String, String) (MSDN).
This method returns all the files as an array of filenames.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With