コード例 #1
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="sourceFileType"></param>
        /// <param name="destinationFileType"></param>
        /// <param name="inputPath"></param>
        /// <param name="outputPath"></param>
        public FileConverter(FileTypeEnum sourceFileType, FileTypeEnum destinationFileType, string inputPath, string outputPath = null)
        {
            // 引数チェック
            if (sourceFileType.Equals(destinationFileType))
            {
                throw new ArgumentException($"{ nameof( sourceFileType ) }と{ nameof( destinationFileType ) }が同じです。");
            }

            if (inputPath.IndexOfAny(Path.GetInvalidPathChars()) > 0)
            {
                throw new ArgumentException("存在しないファイルパスです。", $"{ nameof( inputPath ) } = { inputPath }");
            }

            if ((outputPath != null) && (outputPath.IndexOfAny(Path.GetInvalidPathChars()) > 0))
            {
                throw new ArgumentException("存在しないファイルパスです。", $"{ nameof( outputPath ) } = { outputPath }");
            }

            // プロパティの設定
            SourceFileType      = sourceFileType;
            DestinationFileType = destinationFileType;
            InputPath           = inputPath;
            OutputPath          = outputPath ?? inputPath.GetDirectoryName();

            if (Directory.Exists(inputPath))
            {
                var files = Directory.GetFiles(InputPath);
                if (sourceFileType.Equals(FileTypeEnum.All))
                {
                    TotalCount = files.Count();
                }
                else
                {
                    TotalCount = files.Where(x => x.FileTypeEquals(sourceFileType)).Count();
                }
            }
            else
            {
                TotalCount = inputPath.FileTypeEquals(sourceFileType) ? 1 : 0;
            }
        }