Ejemplo n.º 1
0
 /// <summary>
 /// 封装后的拷贝
 /// </summary>
 /// <param name="dirSource">源文件夹路径</param>
 /// <param name="dirDestination">目标文件夹路径</param>
 private static void CopyUSB(string dirSource, string dirDestination)
 {
     Task.Run(() =>
     {
         string timestamp = Software.TimeStamp.Now;
         Console.WriteLine($"Coying:HackDrive={dirSource},Path={dirDestination + timestamp}");
         TFile.CopyFolder(dirSource, dirDestination + timestamp);
         Console.WriteLine($"Copy:{timestamp} finished");
     });
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 原文件夹有的,目标文件夹没有的文件,复制
        /// </summary>
        /// <param name="source"></param>
        /// <param name="dest"></param>
        private static async void CopyFiles(string source, string dest)
        {
            var i = GetAllFiles(new DirectoryInfo(source));

            foreach (var item in i)
            {
                string u = CutString(source, item.FullName);
                if (!FileEquals(source + u, dest + u))
                {
                    await TFile.SafeCopy(source + u, dest + u).ConfigureAwait(false);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 目标文件夹有,原文件夹没有的文件,删除
        /// </summary>
        /// <param name="source"></param>
        /// <param name="dest"></param>
        /// <param name="backupStr">例:D:\temp\backup</param>
        private static async void CutFiles(string source, string dest, string backupStr)
        {
            var i = GetAllFiles(new DirectoryInfo(dest));

            foreach (var item in i)
            {
                string u = CutString(dest, item.FullName);
                if (!FileEquals(source + u, dest + u))
                {
                    if (Directory.Exists(backupStr))
                    {
                        string x = backupStr + "\\" + item.Name.Substring(0, item.Name.Length - item.Extension.Length) + TimeStamp.Now + item.Extension;
                        await TFile.SafeCopy(dest + u, x).ConfigureAwait(false);
                    }
                    else if (string.IsNullOrEmpty(backupStr))
                    {
                        throw new DirectoryNotFoundException(backupStr);
                    }
                    await TFile.SafeDelete(dest + u).ConfigureAwait(false);
                }
            }
        }