how can I apply to all txt files in the folder. (save to a different folder the same name all the txt files).
this code is only working for a txt file but I want to apply all txt files in a folder its.
I have following code:
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
class MainClass
{
public static void Main(string[] args)
{
string inFile, filePath;
string line;
Console.WriteLine("Input file name to open!");
Console.WriteLine("Sample: d:\\filename.txt");
inFile = Convert.ToString(Console.ReadLine());
StreamReader sr = File.OpenText(inFile);
line = sr.ReadLine();
Console.WriteLine();
Console.WriteLine("Successful file open!...");
Console.WriteLine();
Console.WriteLine("Input file name to save!");
Console.WriteLine("sample: d:\\filename.txt");
filePath = Console.ReadLine();
FileStream file = new FileStream(filePath, FileMode.Create);
StreamWriter sw = new StreamWriter(file);
List<string> lines = new List<string>();
//add all the lines to a list
while ((line = sr.ReadLine()) != null)
{
lines.Add(line);
}
//read the lines you would like to read:
try
{
int numberOne = Int32.Parse(lines[0]);
int numberTwo = Int32.Parse(lines[1]);
int numberThree = Int32.Parse(lines[2]);
int x = numberOne + numberTwo + numberThree;
sw.WriteLine(x);
}
catch { }
Console.ReadLine();
sr.Close();
sw.Close();
}
}
please can you show on the code?