public void RunHandler() { using (HashAlgorithm algorithm = HashAlgorithm.Create(_options.Algorithm)) { if (HashUtils.IsDirectory(_options.Source)) { DirectoryInfo info = new DirectoryInfo(_options.Source); //Run on the base directory RunOnDirectory(info, algorithm); //Run on all subdirectories if (_options.Recursive) { foreach (DirectoryInfo directoryInfo in info.EnumerateDirectories()) { RunOnDirectory(directoryInfo, algorithm); } } } else { //Run on single file FileInfo fileInfo = new FileInfo(_options.Source); if (fileInfo.Exists) { RunOnFile(fileInfo, algorithm); } } } }
/// <summary> /// Constructor /// </summary> /// <param name="options">Parsed command line arguments</param> public RenameHandler(RenameFilesOptions options) { _options = options; string source = HashUtils.IsDirectory(_options.Source) ? _options.Source : Directory.GetCurrentDirectory(); _rootParentDir = new DirectoryInfo(source); _outputDir = new DirectoryInfo(HashUtils.GetOutputDirectory(_options)); if (!_outputDir.Exists) { _outputDir.Create(); } _supportedExtensions = HashUtils.SupportedExtensions; //.Intersect(_options.ExcludedFileExtensions); todo }
/// <summary> /// Run the Rename Handler /// </summary> public void RunHandler() { if (HashUtils.IsDirectory(_options.Source)) { DirectoryInfo info = new DirectoryInfo(_options.Source); using (HashAlgorithm algorithm = HashAlgorithm.Create(_options.Algorithm)) { RunOnDirectory(info, algorithm); if (!_options.Recursive) { return; } foreach (DirectoryInfo directoryInfo in info.EnumerateDirectories("*", SearchOption.AllDirectories)) { RunOnDirectory(directoryInfo, algorithm); } } } else { FileInfo fileInfo = new FileInfo(_options.Source); if (!fileInfo.Exists) { return; } using (HashAlgorithm algorithm = HashAlgorithm.Create(_options.Algorithm)) { RunOnFile(fileInfo, algorithm, CreateFinalDirectoryPath(fileInfo.Directory)); } } }