Warning: mysqli_num_fields() expects parameter 1 to be mysqli_result, boolean given in /www/wwwroot/dev.zhalaotie.com/wp-includes/wp-db.php on line 3215

Warning: mysqli_num_fields() expects parameter 1 to be mysqli_result, boolean given in /www/wwwroot/dev.zhalaotie.com/wp-includes/wp-db.php on line 3215
代码批量替换文件名(C#) File Name Batch Replace by Code (C#) – 扎老铁
Warning: mysqli_num_fields() expects parameter 1 to be mysqli_result, boolean given in /www/wwwroot/dev.zhalaotie.com/wp-includes/wp-db.php on line 3215

Warning: mysqli_num_fields() expects parameter 1 to be mysqli_result, boolean given in /www/wwwroot/dev.zhalaotie.com/wp-includes/wp-db.php on line 3215
Warning: mysqli_num_fields() expects parameter 1 to be mysqli_result, boolean given in /www/wwwroot/dev.zhalaotie.com/wp-includes/wp-db.php on line 3215
class="post-53159 post type-post status-publish format-standard hentry">

代码批量替换文件名(C#) File Name Batch Replace by Code (C#)

 

using System;

namespace FileNameReplace
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            if (args == null || args.Length == 0 || args.Length < 2)
            {
                Console.WriteLine("source dest");
                return;
            }
            //args = new string[] { "原来的文件名要替换的部分", "替换成的内容" };
            string keyword = args[0];
            string newValue = args[1];
            var sourceDir = AppDomain.CurrentDomain.BaseDirectory;
            var files = System.IO.Directory.GetFiles(sourceDir, "*" + keyword + "*", System.IO.SearchOption.AllDirectories);
            for (int i = 0; i < files.Length; i++)
            {
                var file = new System.IO.FileInfo(files[i]);
                var replacedName = file.Name.Replace(keyword, newValue);
                if (file.Name == replacedName)
                {
                    continue;
                }
                string moveTo = System.IO.Path.Combine(file.Directory.FullName, replacedName);
                try
                {
                    file.MoveTo(moveTo);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(String.Format("{0}\t{1}-->{2}\t{3}", file.Name, file.FullName, moveTo, ex.Message));
                }
            }
            var directories = System.IO.Directory.GetDirectories(sourceDir);
            for (int i = 0; i < directories.Length; i++)
            {
                var directory = new System.IO.DirectoryInfo(directories[i]);
                var name = directory.Name.Replace(keyword, newValue);
                if (directory.Name == name)
                {
                    continue;
                }
                string moveTo = System.IO.Path.Combine(directory.Parent.FullName, name);
                try
                {
                    directory.MoveTo(directory.Parent == null ? name : moveTo);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(String.Format("{0}\t{1}-->{2}\t{3}", directory.Name, directory.FullName, moveTo, ex.Message));
                }
            }
            Console.WriteLine("completed");
            //Console.WriteLine ("Hello World!");
        }
    }
}

 

使用:

FileNameReplace “原来的文件名要替换的部分” “替换成的内容”

 

发表评论

电子邮件地址不会被公开。