示例#1
0
        private async Task CompressContents()
        {
            var sourceInfo = new DirectoryInfo(SourceDir);

            ScanHelper.CompressDirectory(sourceInfo.FullName, $"{DestDir}\\{sourceInfo.Name}.zip");

            if (DeleteIfSuccessful)
            {
                var dirFiles   = sourceInfo.GetFiles();
                var dirSubDirs = sourceInfo.GetDirectories();

                foreach (var file in dirFiles.ToList())
                {
                    try
                    {
                        file.Delete();
                    }
                    catch { }
                }

                if (IncludeSubDirectories)
                {
                    foreach (var dir in dirSubDirs.ToList())
                    {
                        try
                        {
                            dir.Delete(true);
                        }
                        catch { }
                    }
                }
            }
        }