日期:2014-05-18  浏览次数:20763 次

请教个改文件名的问题
我有两个数组 ArrayList old ArrayList new 里面存了一一对应的数据。 现在想把C:\ATI 下所有文件查询一下,如果文件名和old里数据一样 把这个文件改名为new对应的名字 有个问题是例如文件名是 abc.txt old里的数据格式是 
abc/01 new中对应数据为 cba/00A 程序最终是要把这个文件名改为 cba.txt 这个问题要如何解决?

------解决方案--------------------
C# code
 string file_name = "abc.txt";
                ArrayList old_array = new ArrayList() { "abc/01", "sss/02" };
                ArrayList new_array = new ArrayList() { "cba/00A","ttt/00B" };
                string file_part = Regex.Match(file_name, @"[^.]+(?=\.)").Value;
                string new_file_name = string.Empty;
                for (int i = 0; i < old_array.Count; i++)
                {
                    Regex reg = new Regex(@"[^/]+(?=/)");
                    string check_str_old = reg.Match(old_array[i].ToString()).Value;
                    if (check_str_old.Equals(file_part))
                    {
                        new_file_name = reg.Match(new_array[i].ToString()).Value;
                        break;
                    }
                    else
                        continue;
                }
                //new_file_name : "cba"