private string GetCanUseName(string newName,string oldName,int num)
{            
    if (!File.Exists(newName))
    {
        return newName;
    }
    else
    {
        //存在                
        string ext = Path.GetExtension(oldName);
        string nameInfo = oldName.Replace(ext, "");
        return GetCanUseName(nameInfo + "_" + (++num) + ext, oldName, ++num);
    }
}

private void button1_Click(object sender, EventArgs e)
{
    string name = "C:\\123\\1.txt";
    string tt = GetCanUseName(name, name, 0);
    MessageBox.Show(tt);
}

相关文章:

  • 2021-11-02
  • 2021-07-14
  • 2022-12-23
  • 2021-09-29
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-29
  • 2021-12-30
  • 2022-12-23
  • 2022-12-23
  • 2021-08-05
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案