Ejemplo n.º 1
0
        public static async void TestMove()
        {
            string path                = "H:\\New folder\\A";
            string targetPath          = "H:\\New folder\\B\\sadasd";
            IList <FileItemInfo> items = new List <FileItemInfo>();

            try
            {
                DirectoryInfo directory = new DirectoryInfo(path);
                var           dirs      = directory.EnumerateDirectories();
                foreach (var dir in dirs)
                {
                    items.Add(new FileItemInfo
                    {
                        FullName    = dir.FullName,
                        Name        = dir.Name,
                        IsDirectory = true
                    });
                }
                var files = directory.EnumerateFiles();
                foreach (var file in files)
                {
                    items.Add(new FileItemInfo
                    {
                        FullName    = file.FullName,
                        Name        = file.Name,
                        IsDirectory = false
                    });
                }
                FileOperationService service = new FileOperationService();
                var result = await service.MoveFileItem(items, targetPath, true);

                foreach (var r in result)
                {
                    Console.WriteLine($"{r.SourceName}\t{r.TargetName}\t{r.IsDirectory}");
                }
                Console.WriteLine("============================");
                result = await service.UndoMove(result, true);

                foreach (var r in result)
                {
                    Console.WriteLine($"{r.SourceName}\t{r.TargetName}\t{r.IsDirectory}");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }