zoukankan      html  css  js  c++  java
  • C# 保存文件如有重名在原名后加(*)

    C#保存文件如有重名加() **(1)

          //Myadd 处理重名
            private string GetNewPathForDupes(string path)
            {
                string directory = Path.GetDirectoryName(path);
                string filename = Path.GetFileNameWithoutExtension(path);
                string extension = Path.GetExtension(path);
                int counter = 1;
                string newFullPath;
                do
                {
                    //string newFilename = "{0}({1}).{2}".FormatWith(filename, counter, extension);
                    string newFilename = string.Format("{0}({1}){2}", filename, counter, extension);
                    newFullPath = Path.Combine(directory, newFilename);
                    counter++;
                } while (System.IO.File.Exists(newFullPath));
                return newFullPath;
            }
          private string GetNewPathForDupes(string path)
            {
               string newFullPath = path.Trim();
                //if (System.IO.File.Exists(path))
                //    MessageBox.Show("存在");
                //else
                //    MessageBox.Show("不存在");
                if (System.IO.File.Exists(path))
                {
                    string directory = Path.GetDirectoryName(path);
                    string filename = Path.GetFileNameWithoutExtension(path);
                    string extension = Path.GetExtension(path);
                    int counter = 1;
                    do
                    {
                        //string newFilename = "{0}({1}).{2}".FormatWith(filename, counter, extension);
                        string newFilename = string.Format("{0}({1}){2}", filename, counter, extension);
                        newFullPath = Path.Combine(directory, newFilename);
                        counter++;
                    } while (System.IO.File.Exists(newFullPath));
                }
                return newFullPath;
            }
  • 相关阅读:
    java得到当前日期的前一天或后一天
    java通过年月得到该月每一天的日期
    前后端分离的跨域请求问题解决
    关于java中分割字符串
    Linux终端命令
    eclipse中tomcat可以start启动,无法debug启动的解决
    通过DOS界面查看电脑上端口使用情况
    前端css
    mysql数据库
    IO阻塞
  • 原文地址:https://www.cnblogs.com/yimeishui/p/5873159.html
Copyright © 2011-2022 走看看