如何更改多个文件的路径c#

如何更改多个文件的路径c#,c#,windows,filepath,C#,Windows,Filepath,在此代码中,我从用户选择的路径获取文件名,我想编辑文本文件并将其保存为文本,但我希望它是(filename+new)。txt我的代码获取文件名。txtnew: private void button1_Click(object sender, EventArgs e) { folderBrowserDialog1.ShowDialog(); string[] fileArray = System.IO.Directory.GetFiles(folderBrowserDialog

在此代码中,我从用户选择的路径获取文件名,我想编辑文本文件并将其保存为文本,但我希望它是
(filename+new)。txt
我的代码获取
文件名。txtnew

private void button1_Click(object sender, EventArgs e)
{
    folderBrowserDialog1.ShowDialog();

    string[] fileArray = System.IO.Directory.GetFiles(folderBrowserDialog1.SelectedPath);
    foreach (string filename in fileArray)
    {
        richTextBox1.Text = "";
        //string path = @"C:\Users\rabih\Desktop\uni\IR\textNoStopWords"+".txt ";
        string path = filename + "new";
        richTextBox1.Text = System.IO.File.ReadAllText(filename);
        string st = richTextBox1.Text;
        string[] split = st.Split(' ');
        foreach (string s in split)
        {
            if (!Stopwords.Contains(s.ToLower()))
            {
                //richTextBox2.Text += s + " ";
            }
        }
        richTextBox2.Text += path + " \n";
        using (File.Create(path)) ;
        richTextBox2.SaveFile(path, RichTextBoxStreamType.RichText);
    }
}

您可以按
拆分文件名,并构造新的
文件名
,如以下代码所示:

private static string GetNewFileName(string oldFileName)
{
    string[] splitedFileName = oldFileName.Split('.');

    return string.Concat(splitedFileName[0], "new.", splitedFileName[1]);
}
在代码中调用
GetNewFileName

string newFileName = GetNewFileName(filename);

我希望这能帮助您解决这个问题。

您可以考虑使用
GetFileNameWithoutExtension
只获取不带扩展名的文件名,然后添加“New”。