Use SearchOption.AllDirectories to list filenames from all directories if you have subdirectories in the given folder.
try
{
string[] saFiles = Directory.GetFiles(ConfigurationSettings.AppSettings["INPUT_FOLDER_PATH"], "*.*", SearchOption.AllDirectories);
// Display all the files.
foreach (string file in saFiles)
{
using (StreamWriter writer = new StreamWriter(ConfigurationSettings.AppSettings["OUTPUT_FILE_NAME"],true))
{
writer.WriteLine(Path.GetFileNameWithoutExtension(file));
}
Console.WriteLine(Path.GetFileNameWithoutExtension(file));
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
try
{
string[] saFiles = Directory.GetFiles(ConfigurationSettings.AppSettings["INPUT_FOLDER_PATH"], "*.*", SearchOption.AllDirectories);
// Display all the files.
foreach (string file in saFiles)
{
using (StreamWriter writer = new StreamWriter(ConfigurationSettings.AppSettings["OUTPUT_FILE_NAME"],true))
{
writer.WriteLine(Path.GetFileNameWithoutExtension(file));
}
Console.WriteLine(Path.GetFileNameWithoutExtension(file));
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
No comments:
Post a Comment