//public static void zAddSourceDirectoryFiles(this Dictionary<string, List<FileGroup_v2>> fileGroups, string directory) //{ // fileGroups.zKeyListAdd(GetFiles(directory).Select(fileGroup => { fileGroup.SourceDirectoryFile = true; return fileGroup; }), fileGroup => fileGroup.BaseFilename); //} public IEnumerable <FileGroup_v2> GetNotBonusFiles(string directory) { Func <EnumDirectoryInfo, EnumDirectoryFilter> directoryFilter = dir => { if (GetBonusDirectoryInfo(dir.SubDirectory).IsBonusDirectory) { return new EnumDirectoryFilter { Select = false, RecurseSubDirectory = false } } ; else { return new EnumDirectoryFilter { Select = true, RecurseSubDirectory = true } }; }; IEnumerable <EnumFileInfo> files = zdir.EnumerateFilesInfo(directory, directoryFilters: new Func <EnumDirectoryInfo, EnumDirectoryFilter>[] { directoryFilter }); foreach (EnumFileInfo file in files) { FileNumber filenameNumberInfo = FileNumber.GetFileNumber(file.File); string baseFilename = filenameNumberInfo.BaseFilename; bool badFile = false; if (file.SubDirectory == __badFileDirectory) { baseFilename = __badFileDirectory + "\\" + baseFilename; badFile = true; } yield return(new FileGroup_v2 { Directory = directory, SubDirectory = file.SubDirectory, File = file.File, BaseFilename = baseFilename, Number = filenameNumberInfo.Number, BadFile = badFile //PrintInfo = PrintIssue.GetPrintInfo(zPath.GetFileNameWithoutExtension(filenameNumberInfo.BaseFilename)) }); } }
// directory is pdf directory public static IEnumerable <string> GetQuestionFiles(string directory) { SortedDictionary <string, string> files = new SortedDictionary <string, string>(); // question-01-2015-016.json directory = GetQuestionsDirectory(directory); if (!zDirectory.Exists(directory)) { throw new PBException($"directory not found \"{directory}\""); } foreach (string file in zDirectory.EnumerateFiles(directory, "question-*.json")) { FileNumber fileNumber = FileNumber.GetFileNumber(file); if (!files.ContainsKey(fileNumber.BaseFilename)) { files.Add(fileNumber.BaseFilename, null); } } return(files.Keys); }
public static Dictionary <string, List <FileGroup> > GetFileGroups(IEnumerable <EnumDirectoryInfo> directories) { Dictionary <string, List <FileGroup> > fileGroups = new Dictionary <string, List <FileGroup> >(StringComparer.InvariantCultureIgnoreCase); foreach (EnumDirectoryInfo directoryInfo in directories) { //Trace.WriteLine("get files from \"{0}\"", directoryInfo.Directory); // followDirectoryTree ???? // followDirectoryTree: dir => { } var query = zdir.EnumerateFilesInfo(directoryInfo.Directory) .Select( file => { FileNumber filenameNumberInfo = FileNumber.GetFileNumber(file.File); string baseFilename = filenameNumberInfo.BaseFilename; bool badFile = false; if (file.SubDirectory == __badFileDirectory) { baseFilename = __badFileDirectory + "\\" + baseFilename; badFile = true; } return(new FileGroup { DirectoryInfo = directoryInfo, SubDirectory = file.SubDirectory, File = file.File, BaseFilename = baseFilename, Number = filenameNumberInfo.Number, BadFile = badFile //PrintInfo = PrintIssue.GetPrintInfo(zPath.GetFileNameWithoutExtension(filenameNumberInfo.BaseFilename)) }); } ); fileGroups.zKeyListAdd(query, fileGroup => fileGroup.BaseFilename); } return(fileGroups); }
private Dictionary <string, List <FileGroup_v1> > GetFileGroups_v1(IEnumerable <DirectoryGroup> directories) { Dictionary <string, List <FileGroup_v1> > fileGroups = new Dictionary <string, List <FileGroup_v1> >(); foreach (DirectoryGroup directoryGroup in directories) { var query = zDirectory.EnumerateFiles(directoryGroup.Directory, "*.*", SearchOption.AllDirectories).Select( file => { //FilenameNumberInfo filenameNumberInfo = zpath.PathGetFilenameNumberInfo(file); FileNumber filenameNumberInfo = FileNumber.GetFileNumber(file); return(new FileGroup_v1 { DirectoryGroup = directoryGroup, File = file, BaseFilename = filenameNumberInfo.BaseFilename, Number = filenameNumberInfo.Number }); } ); fileGroups.zKeyListAdd(query, fileGroup => fileGroup.BaseFilename); } return(fileGroups); }
public IEnumerable <FileGroup_v2> GetFiles(string directory, FileFilter fileFilter) { // not bonus files List <Func <EnumDirectoryInfo, EnumDirectoryFilter> > directoryFilters = new List <Func <EnumDirectoryInfo, EnumDirectoryFilter> >(); directoryFilters.Add(InfoDirectoryFilter); if (fileFilter == FileFilter.NotBonusFiles) { directoryFilters.Add(NotBonusDirectoryFilter); } //if (fileFilter == FileFilter.NotBonusFiles) //{ // // skip bonus directories // directoryFilter = dir => // { // if (GetBonusDirectoryInfo(dir.SubDirectory).IsBonusDirectory) // return new EnumDirectoryFilter { Select = false, RecurseSubDirectory = false }; // else // return new EnumDirectoryFilter { Select = true, RecurseSubDirectory = true }; // }; //} // bonus files int bonusDirectoryLevel = 0; int bonusSubDirectoryLength = 0; string bonusSubDirectory = null; Action <EnumDirectoryInfo> followDirectoryTree = null; if (fileFilter == FileFilter.BonusFiles) { followDirectoryTree = dir => { if (bonusDirectoryLevel == 0) { if (dir.SubDirectory != null) { BonusDirectoryInfo bonusDirectoryInfo = GetBonusDirectoryInfo(dir.SubDirectory); if (bonusDirectoryInfo.IsBonusDirectory) { bonusDirectoryLevel = dir.Level; bonusSubDirectoryLength = dir.SubDirectory.Length + 1; bonusSubDirectory = bonusDirectoryInfo.Directory; } } } else if (dir.SubDirectory == null && dir.Level == bonusDirectoryLevel) { bonusDirectoryLevel = 0; bonusSubDirectoryLength = 0; bonusSubDirectory = null; } }; } IEnumerable <EnumFileInfo> files = zdir.EnumerateFilesInfo(directory, //directoryFilters: directoryFilter != null ? new Func<EnumDirectoryInfo, EnumDirectoryFilter>[] { directoryFilter } : null, directoryFilters: directoryFilters, followDirectoryTrees: followDirectoryTree != null ? new Action <EnumDirectoryInfo>[] { followDirectoryTree } : null); foreach (EnumFileInfo file in files) { FileNumber filenameNumberInfo = FileNumber.GetFileNumber(file.File); string baseFilename = filenameNumberInfo.BaseFilename; bool badFile = false; if (file.SubDirectory == __badFileDirectory) { baseFilename = __badFileDirectory + "\\" + baseFilename; badFile = true; } string subDirectory = file.SubDirectory; if (fileFilter == FileFilter.BonusFiles) { if (bonusDirectoryLevel == 0) { continue; } subDirectory = file.SubDirectory.Length > bonusSubDirectoryLength?file.SubDirectory.Substring(bonusSubDirectoryLength) : null; if (bonusSubDirectory != null) { if (subDirectory != null) { subDirectory = zPath.Combine(bonusSubDirectory, subDirectory); } else { subDirectory = bonusSubDirectory; } } } //switch (fileFilter) //{ // case FileFilter.NotBonusFiles: // break; // case FileFilter.BonusFiles: // break; // case FileFilter.AllFiles: // break; //} yield return(new FileGroup_v2 { Directory = directory, SubDirectory = subDirectory, File = file.File, BaseFilename = baseFilename, Number = filenameNumberInfo.Number, BadFile = badFile //PrintInfo = PrintIssue.GetPrintInfo(zPath.GetFileNameWithoutExtension(filenameNumberInfo.BaseFilename)) }); } }
public IEnumerable <FileGroup_v2> GetBonusFiles(string directory) { int bonusDirectoryLevel = 0; int bonusSubDirectoryLength = 0; string bonusSubDirectory = null; Action <EnumDirectoryInfo> followDirectoryTree = dir => { if (bonusDirectoryLevel == 0) { //if (dir.SubDirectory != null && IsBonusDirectory(dir.SubDirectory)) if (dir.SubDirectory != null) { BonusDirectoryInfo bonusDirectoryInfo = GetBonusDirectoryInfo(dir.SubDirectory); if (bonusDirectoryInfo.IsBonusDirectory) { bonusDirectoryLevel = dir.Level; bonusSubDirectoryLength = dir.SubDirectory.Length + 1; bonusSubDirectory = bonusDirectoryInfo.Directory; } } } else if (dir.SubDirectory == null && dir.Level == bonusDirectoryLevel) { bonusDirectoryLevel = 0; bonusSubDirectoryLength = 0; bonusSubDirectory = null; } }; IEnumerable <EnumFileInfo> files = zdir.EnumerateFilesInfo(directory, followDirectoryTrees: new Action <EnumDirectoryInfo>[] { followDirectoryTree }); foreach (EnumFileInfo file in files) { if (bonusDirectoryLevel != 0) { FileNumber filenameNumberInfo = FileNumber.GetFileNumber(file.File); string subDirectory = file.SubDirectory.Length > bonusSubDirectoryLength?file.SubDirectory.Substring(bonusSubDirectoryLength) : null; if (bonusSubDirectory != null) { if (subDirectory != null) { subDirectory = zPath.Combine(bonusSubDirectory, subDirectory); } else { subDirectory = bonusSubDirectory; } } yield return(new FileGroup_v2 { Directory = directory, SubDirectory = subDirectory, File = file.File, BaseFilename = filenameNumberInfo.BaseFilename, Number = filenameNumberInfo.Number //PrintInfo = PrintIssue.GetPrintInfo(zPath.GetFileNameWithoutExtension(filenameNumberInfo.BaseFilename)) }); } } }
public async Task <object> GetFileNumber(object file) { return(FileNumber.GetFileNumber((string)file)); }