Hello everyone!
I need to get only file name wit extension without path
Could you help me?
I need to get only file name wit extension without path
C#:
private void button9_Click(object sender, EventArgs e)
{
string rootFolder = @"C:\Users\Anton\Desktop\?#folder";
string pattern = @"\b(ArtId=[0-9]*)\b";
using (StreamWriter sw = File.CreateText(@"C:\Users\Anton\Desktop\?#folder\target.txt"))
foreach (var file in Directory.EnumerateFiles(rootFolder, "*.txt", SearchOption.AllDirectories))
{
using (StreamReader sr = new StreamReader(file, System.Text.Encoding.Default))
{
string line;
while ((line = sr.ReadLine()) != null)
{
string newstring = line.Substring(0, 8);
Match match = Regex.Match(line, pattern, RegexOptions.IgnoreCase);
if (match.Success)
sw.WriteLine(file + " " + newstring + " " + match.Value);
else
sw.Write("");
}
}
}
Console.Write("File txt is ready");
Console.ReadKey();
}
}
Could you help me?