Search code examples
c#streamreader

Read Specific textfile in streamreader


I want to read many delimited files from a folder. However, the calling in the code is per one textfile only.

System.IO.StreamReader file =new System.IO.StreamReader(@"C:\Orders\OrdersForImport.txt");

I want the "OrdersForImport.txt" to be change.

my textfiles are OrdersForImport, OrdersForImport1, OrdersForImport2, OrdersForImport3, etc.

it is constant that the ".txt" extention will not be change. only the filenames will be change


Solution

  • Thanks for all answer,

    here is what I done to read all delimited files in a folder.

    FileSystemWatcher fileSystemWatcher = new FileSystemWatcher();

    fileSystemWatcher.Path = @"C:\Orders\";

    string[] dirs = System.IO.Directory.GetFiles(fileSystemWatcher.Path, "*.txt");

    System.IO.StreamReader files = new System.IO.StreamReader(dir);

    PS> I tried all your answers