using DiscUtils.Iso9660; using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace FileCount { class Program { static void Main(string[] args) { string directoryPath = @"D:\test\"; CreateIso("test", @"C:\Users\developer\Desktop\test.iso", directoryPath, new string[] { directoryPath }); Console.ReadKey(); } public static List<string> GetAllFiles(string directoryPath) { var result = new List<string>(); if (Directory.Exists(directoryPath)) { result.AddRange(Directory.GetFiles(directoryPath)); foreach (var dir in Directory.GetDirectories(directoryPath)) { result.AddRange(GetAllFiles(dir)); } } return result; } static string GetSubName(string rootDirectory, string path) { if (!path.StartsWith(rootDirectory)) new ArgumentException("Given parameters are not in same root directory!"); var output = path.Substring(rootDirectory.Length); if (output[0] == '\\') output = output.Substring(1); return output; } static void CreateIso(string volumeIdentifier, string output, string rootDirectory, string[] paths) { var builder = new CDBuilder(); builder.UseJoliet = true; builder.VolumeIdentifier = volumeIdentifier; if (!Directory.Exists(rootDirectory)) throw new DirectoryNotFoundException("The directory not found: " + rootDirectory); if (!paths.All(q => q.StartsWith(rootDirectory))) new ArgumentException("Given parameters are not in same root directory!"); var files = new List<string>(); foreach (var path in paths) { var fileAttr = File.GetAttributes(path); if (fileAttr.HasFlag(FileAttributes.Directory)) files.AddRange(GetAllFiles(path)); else files.Add(path); } foreach (var file in files.Distinct()) { builder.AddFile(GetSubName(rootDirectory, file), File.ReadAllBytes(file)); } builder.Build(output); } } }
21 Ekim 2019
C# ISO Oluşturma
DiscUtils