最后这些图片名称就是:
B1063_001_Nike.jpg
B1063_002_Nike.jpg
B1063_003_Nike.jpg
……问题出在:如何根据ListView里的数据来批量重命名?  而不是根据FolderBrowserDialog把整个目录文件批量命名。我出问题的具体代码请到:点击这里……

解决方案 »

  1.   


                //看的有点不太明白
                string[] filePaths;//文件列表
                string nameFormat = "B1063_{$Num}_Nike";
                int beginNum = 1;
                int numLen = 3;            for (int i = 0; i < filePaths.Length; i++)
                {
                    string file = filePaths[i];
                    string path = file.Substring(0, file.LastIndexOf('\\'));//路径
                    string fn = file.Substring(file.LastIndexOf('\\')+1);//文件名
                    string ext = fn.Substring(fn.LastIndexOf('.'));//文件后缀                string newFile = path + nameFormat.Replace("{$Num}", beginNum.ToString().PadLeft(numLen, '0')) + ext;//新文件名
                    File.Move(file, newFile);//改文件名                //newFile 
                }
      

  2.   

                string[] filePaths;//文件列表
                string nameFormat = "B1063_{$Num}_Nike";
                int beginNum = 1;
                int numLen = 3;            string toPath = @"d:\aaaaa";
                if (!Directory.Exists(toPath)) Directory.CreateDirectory(toPath);            for (int i = 0; i < filePaths.Length; i++)
                {
                    string file = filePaths[i];
                    string path = file.Substring(0, file.LastIndexOf('\\'));//路径
                    string fn = file.Substring(file.LastIndexOf('\\') + 1);//文件名
                    string ext = fn.Substring(fn.LastIndexOf('.'));//文件后缀                string newFile = toPath + nameFormat.Replace("{$Num}", beginNum.ToString().PadLeft(numLen, '0')) + ext;//新文件名                File.Move(file, newFile);//剪切至 newFile                File.WriteAllBytes(newFile, File.ReadAllBytes(file));//复制
                }