现在的位置: 首页 > 综合 > 正文

c# 创建不同的文件名

2013年04月03日 ⁄ 综合 ⁄ 共 1017字 ⁄ 字号 评论关闭

按钮单击事件

Windows 7 的效果:

新建文件 副本; 新建文件 副本 副本;新建文件 副本 副本 副本;

 private void bnt_Click(object sender, EventArgs e)
{
           
string listVs = 路径名;
           
bool w = true;
           
string x = "新建文件";
           
string s = " 副本";
           
while (w == true)
            {
               
if (File.Exists(listVs + "//" + x + ".txt") == true)
                {
                    x
+= s;
                    w
= true;
                }
               
else
                {
                   
try
                    {
                        File.CreateText(listVs
+ "//" + x + ".txt");
                        w
= false;
                    }
                   
catch (Exception)
                    {
                        w
= true;
                    }
                }
            }
           
//GetListViewItem(listVs, imageList2, listView1);
           
//for (int i = 0; i < listView1.Items.Count; i++ )
           
//{
           
//    if (listView1.Items[i].Text == x + ".txt")
           
//    {
           
//        listView1.Items[i].BeginEdit();
           
//        break;
           
//    }
              
           
//}
         
}

抱歉!评论已关闭.