-2
namespace FileMove2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Which folder would you like to move files from?");
            string sourcePath = Console.ReadLine();
            Console.Write("Which folder would you like to move files to?");
            string targetPath = Console.ReadLine();

            MoveDirectory(sourcePath, targetPath);
        }
                static void MoveDirectory(string sourcePath, string targetPath)

            { 
                if (!System.IO.Directory.Exists(targetPath))
                {
                    System.IO.Directory.CreateDirectory(targetPath);
                }

                if (System.IO.Directory.Exists(sourcePath))
                {
                    string[] files = System.IO.Directory.GetFiles(sourcePath, "*.*", System.IO.SearchOption.AllDirectories);

                    foreach (string f in files)
                    {
                        System.IO.File.Move(f, targetPath);
                    }
                }
            }
    }
}
4

2 に答える 2