static void Main(string[] args) { do { Console.WriteLine("Paste your \\pf\\fighter dircetory and press enter. EX: \"F:\\Project+\\pf\\fighter\""); Console.Write("Fighter Path: "); string directory = Console.ReadLine(); //Get directory to look for pac files try { foreach (string d in Directory.GetDirectories(directory)) //For each folder in the directory { Console.WriteLine("Found folder " + d); foreach (string filePath in Directory.GetFiles(d)) //For each file in the directory folders { var name = new FileInfo(filePath).Name; //name is .pac file names name = name.ToLower(); //Set .pac names to lower case bool containsInt = name.Any(char.IsDigit); //Check if the .pac files contain a number bool containsAlt = name.Contains("alt"); //Check if there are AltR or AltZ files bool containsExtra = name.Contains("kirby") || name.Contains("spy") || name.Contains("etc"); //Check for kirby files, spy files, and etc files if (containsAlt == true && containsExtra == false || containsInt == true && containsExtra == false) //If pac file names contain a number, is an alt, and doesn't contain spy, etc, or is a kirby costume file { Console.WriteLine("Deleting file " + filePath); File.Delete(filePath); //Delete files } } } } catch (Exception e) { Console.WriteLine("The process failed: {0}", e.Message); } Console.WriteLine("Done! \n\n" + "Press Enter to continue or type \"exit\" to close the program"); } while (Console.ReadLine().ToLower() != "exit"); }
private void ImportFile(string filePattern, FileSet fs) { var fileNameReplacement = String.Empty; if (filePattern.Contains("=")) { fileNameReplacement = filePattern.Substring(0, filePattern.IndexOf("=")); filePattern = filePattern.Substring(filePattern.IndexOf("=") + 1); } var di = new DirectoryInfo(Path.Combine(".", Path.GetDirectoryName(filePattern))); filePattern = Path.GetFileName(filePattern); var matchingFiles = new FileInfo[] { }; if (di.Exists) { matchingFiles = di.GetFiles(filePattern); } if (!matchingFiles.Any()) { var curColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("\n\nWARNING:\n\n - No INPUT files matched {0} in {1}\n", filePattern, di.FullName); var fsf = new FileSetFile(); fsf.RelativePath = Path.GetFileName(filePattern); fs.FileSetFiles.Add(fsf); Console.ForegroundColor = curColor; } foreach (var fi in matchingFiles) { var fsf = new FileSetFile(); fsf.RelativePath = String.IsNullOrEmpty(fileNameReplacement) ? fi.Name : fileNameReplacement; fsf.OriginalRelativePath = fi.FullName.Substring(this.SSoTmeProject.RootPath.Length).Replace("\\", "/"); fs.FileSetFiles.Add(fsf); if (fi.Exists) { if (fi.IsBinaryFile()) { fsf.ZippedBinaryFileContents = File.ReadAllBytes(fi.FullName).Zip(); } else { fsf.ZippedFileContents = File.ReadAllText(fi.FullName).Zip(); } } else { var curColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("INPUT Format: {0} did not match any files in {1}", filePattern, di.FullName); Console.ForegroundColor = curColor; } } }
public IEnumerable <ValidationError> ValidateFile(string filePath) { var rtn = new List <ValidationError>(); var file = new FileInfo(filePath); // Check that the file exists first, there's no point in continuing if it doesn't exist if (!file.Exists) { rtn.Add(new ValidationError { Description = "The file does not exist", ErrorSeverity = ErrorSeverity.Error }); return(rtn); } IEnumerable <FileInfo> configFiles = new FileInfo[0]; try { if (file.Directory != null) { configFiles = file.Directory.GetFiles("Folder.config", SearchOption.TopDirectoryOnly); } } catch (UnauthorizedAccessException) { // We may not have been allowed to read the directory, in which // case we will get an UnauthorizedAccessException thrown. } catch (IOException) { // We may not have been allowed to read the directory, in which // case we will get an UnauthorizedAccessException thrown. } var currentFolderConfig = configFiles.Any() ? Serializer.Deserialize <FolderConfig>(File.ReadAllText(configFiles.First().FullName)) : null; if (currentFolderConfig == null || !currentFolderConfig.Schemas.Any()) { return(rtn); } var validator = new XsdValidator(); foreach (var schema in currentFolderConfig.Schemas) { if (Path.IsPathRooted(schema)) { validator.AddSchema(schema); } else { if (file.Directory != null) { validator.AddSchema(Path.Combine(file.Directory.FullName, schema)); } } } validator.IsValid(filePath); rtn.AddRange(validator.Errors.Select(e => new ValidationError { Description = e, ErrorSeverity = ErrorSeverity.Error })); rtn.AddRange(validator.Warnings.Select(e => new ValidationError { Description = e, ErrorSeverity = ErrorSeverity.Warning })); return(rtn); }