/// <summary> /// visits the directory, recursivery /// </summary> /// <param name="basePath"></param> /// <param name="ct"></param> /// <returns></returns> public static async IAsyncEnumerable <Fsentry> VisitAsync(string basePath, [EnumeratorCancellation] CancellationToken ct = default) { var q = new DirsFilesStack(); await q.EnumAndPushAsync(basePath, Filepath.Empty, ct); while (q.HasMore) { var entry = q.Pop(); yield return(entry); if (entry.Event != FsentryEvent.EnterDir) { continue; } q.PushLeavingDir(entry); if (entry.Command == FsentryCommand.Advance) { var name = Filepath.Parse(Path.GetFileName(entry.FullPathString)); var relativeDir = entry.RelativePath.Parent.Combine(name.Items); await q.EnumAndPushAsync(entry.FullPathString, relativeDir, ct); } else // skip requested { // nop. skip. } } }
//// This function demonstrates that we can add a comment to (nearly) every paragraph if we like. public static void AddToEveryPara(Document doc) { ConsoleC.WriteLine(ConsoleColor.White, "Trying to write a comment on all the paragraphs!"); //// Load the default instance of Document class. // Document doc = LoadDocument.Default(); for (int i = 1; i < doc.Paragraphs.Count; i++) { // Add a comment. try { object text = "This is a comment on Paragraph " + i + "."; doc.Comments.Add(doc.Paragraphs[i].Range, ref text); ConsoleC.WriteLine(ConsoleColor.Green, "Added a comment on Paragraph " + i + "!"); } catch (Exception ex) { ConsoleC.WriteLine(ConsoleColor.Red, "Failed to add a comment to Paragraph " + i + " — " + ex.ToString()); } } //Save to a new file. doc.SaveAs2(Filepath.Full().Replace(".docx", "_2.docx")); }
public void Test_Empty() { var path = Filepath.Parse(""); Assert.IsTrue(path.Prefix is PathPrefix.Empty); Assert.AreEqual("", path.ToString()); }
public void Test_Simple_Afile() { var path = Filepath.Parse("file.txt"); Assert.IsFalse(path.Absolute); Assert.AreEqual("file.txt", path.ToString("/")); }
public string ExtractSeriesName(MediaFile ie) { reset(); this.ie = ie; // Read plain configurationFilePath string filename = System.IO.Path.GetFileNameWithoutExtension(ie.Filename); filename = NameCleanup.RemoveReleaseGroupTag(filename); folders = Filepath.extractFoldernamesFromPath(ie.FilePath.Path); if (ie.inSeasonFolder() && folders.Length > 2) { if (!Regex.IsMatch(folders[folders.Length - 2], pathBlacklist, RegexOptions.IgnoreCase)) { return(folders[folders.Length - 2]); } } extractNameFromSeasonsFolder(); extractNameFromString(filename); if (folders.Length != 0) { extractNameFromString(folders[folders.Length - 1]); } fallbackFolderNames(); name = NameCleanup.Postprocessing(name); if (name == null) { return(""); } return(name); }
private void Update(EvaluationContext context) { var content = Content.GetValue(context); var filepath = Filepath.GetValue(context); if (content != _lastContent) { Log.Debug("Writing file " + filepath); try { File.WriteAllText(filepath, content); } catch (Exception e) { Log.Error($"Failed to write file {filepath}:" + e.Message); } _lastContent = content; } else { Log.Debug("Just updating???"); } Result.Value = Content.GetValue(context); OutFilepath.Value = filepath; // Forward so it can be triggered }
static void Main(string[] args) { if (args.Length > 0) { if (File.Exists(args[0])) { args[0] = Filepath.goUpwards(args[0], 1); } if (!Directory.Exists(args[0])) { AttachConsole(ATTACH_PARENT_PROCESS); Console.Out.WriteLine(); Console.Out.WriteLine("Series Renamer command line argument(s):"); Console.Out.WriteLine("\"Series Renamer.exe [Path]\": Opens the program in the folder [Path]."); Console.Out.WriteLine("\"Series Renamer.exe /help\": Displays this help message."); return; } } Console.Out.WriteLine(""); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Form1.Instance = new Form1(args); Application.Run(Form1.Instance); }
static void Main(string[] args) { //// Load a document we can play with. Document doc = LoadDocument.Default(); DocumentCheckSpelling.DocCheckSpelling(doc); // InlineLists.RunTests(); InlineLists.DetectAll(doc); // Comments.AddToEveryPara(doc); Headers.DetectHeaders(doc); Headers.DetectLineSpacingAfterBullets(doc); Language.LanguageChecker(doc); //// Save to a new file. doc.SaveAs2(Filepath.Full().Replace(".docx", "_2.docx")); //// Keep the console open even when the program has finished. ConsoleC.WriteLine(ConsoleColor.Green, "\nThe program has finished."); Console.ReadLine(); }
public static Word.Document Default() { try { object fileName = Filepath.Full(); Word.Application wordApp = new Word.Application { Visible = true }; Document aDoc = wordApp.Documents.Open(ref fileName, ReadOnly: false, Visible: true); aDoc.Activate(); Word.Application wordObject = (Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application"); Application word = (Microsoft.Office.Interop.Word.Application)wordObject; word.Visible = true; word.ScreenUpdating = false; return(word.ActiveDocument); } catch { throw new Exception("Error loading default document!"); } }
public void Test_Canonicalize() { { var path = Filepath.Parse("./../dir/.../xxx/../file.txt"); Assert.AreEqual("dir/.../file.txt", path.Canonicalize().ToString("/")); } }
static void Xmp1(string[] args) { var inputPath = (1 <= args.Length) ? args[0] : Directory.GetCurrentDirectory(); var filepath = Filepath.Parse(inputPath); Console.WriteLine($"input path = {filepath}"); Console.WriteLine("======================================================="); Console.WriteLine($" prefix : {filepath.Prefix}"); Console.WriteLine($"is absolute?: {filepath.IsAbsolute}"); for (var i = 0; i < filepath.Items.Count; i++) { Console.WriteLine($" item {i} : {filepath.Items[i]}"); } Console.WriteLine("======================================================="); Console.WriteLine($" last item : {filepath.LastItem}"); Console.WriteLine($" has ext?: {filepath.HasExtension}"); Console.WriteLine($" last item without ext: {filepath.LastItemWithoutExtension}"); Console.WriteLine($" extension : {filepath.Extension}"); }
private string GenerateFullPath() { var checkedFilePath = Filepath.TrimEnd(new char['\\']) + "\\"; var checkedFileName = Filename.EndsWith(".xml") ? Filename : Filename + ".xml"; return(checkedFilePath + checkedFileName); }
public void Test_Simple_0() { var path = Filepath.Parse("/"); Assert.IsTrue(path.Absolute); Assert.AreEqual("/", path.ToString("/")); Assert.AreEqual("\\", path.ToString("\\")); }
public void Test_Simple_WithBackSlashes() { var path = Filepath.Parse(@"a/\/b///c/\/\/"); Assert.IsFalse(path.IsAbsolute); Assert.AreEqual(3, path.Items.Count); Assert.AreEqual("c", path.Items[2]); }
public override string ToString() { if (!Filepath.Contains(".")) { Filepath += "." + DefaultFileExtension; } return($"{Type},{Layer},{Origin},\"{Filepath.Replace('\\', '/')}\",{StartPosition.X.ToString(Constants.CULTUREINFO)},{StartPosition.Y.ToString(Constants.CULTUREINFO)}"); }
private static Filepath GetTempDir() => Filepath.Parse(System.IO.Path.GetTempPath()) .Combine(_AsItems("FsentryTestDir_" + DateTime.Now.ToString("yyyyMMdd-HHmmss") + "_" + NextTempDirSeq())) .Canonicalize() .Also(self => { // 安全そうなパスであることをできるだけチェック Assert.IsTrue(self.IsAbsolute); Assert.IsTrue(2 <= self.Items.Count); });
public void Test_Simple_2() { var path = Filepath.Parse(@"a/\/b///c/\/\/"); Assert.IsFalse(path.Absolute); Assert.AreEqual(3, path.Items.Length); Assert.AreEqual("c", path.Items[2]); }
public bool IsHost() { //Does file name end with ".Tests.csproj" return(Filepath.EndsWith(".Tests.csproj") || Text.Contains("349c5851-65df-11da-9384-00065b846f21") || //IsWebApp/Site/MVC/WebRole IsInHostPath(Filepath)); // is in services.json }
public DalFilepath MapToDal(Filepath entity) { return(new DalFilepath { Id = entity.id, Path = entity.path, Lib_id = entity.lib_id }); }
public void Test_Simple_Absolute_1() { var path = Filepath.Parse("/"); Assert.IsTrue(path.Prefix is PathPrefix.Empty); Assert.IsTrue(path.Absolute); Assert.AreEqual(0, path.Items.Length); Assert.AreEqual("/", path.ToString("/")); }
private string Find_history_file_by_id(string id) { var filepaths = Directory.GetFiles(_path); var filepath = filepaths.FirstOrDefault(fp => Filepath.Matches_id(fp, id)); if (filepath == null) { throw new ApplicationException($"Invalid history id '{id}'!"); } return(filepath); }
// mandatory since ModuleCacheKey is used as a dictionnary key public override int GetHashCode() { int hashcode = Name.GetHashCode() ^ Flags.GetHashCode(); if (Filepath != null) { hashcode ^= Filepath.GetHashCode(); } return(hashcode); }
public string Map_name_to_id(string name) { var filepaths = Directory.GetFiles(_path); var filepath = filepaths.FirstOrDefault(fp => Filepath.Matches_name(fp, name)); if (filepath == null) { throw new ApplicationException($"Invalid history name '{name}'!"); } return(Filepath.Extract_id(filepath)); }
public override int GetHashCode() { unchecked { var result = Language.GetHashCode(); result = (result * 397) ^ Name.GetHashCode(); result = (result * 397) ^ Filepath.GetHashCode(); result = (result * 397) ^ _internalConfigList.GetHashCode(); return(result); } }
private async Task SetupPathAsync(Filepath absPath) { if (absPath.HasExtension) { System.IO.Directory.CreateDirectory(absPath.Parent.ToString()); await System.IO.File.WriteAllTextAsync(absPath.ToString(), "some file.", System.Text.Encoding.UTF8); } else { System.IO.Directory.CreateDirectory(absPath.ToString()); } }
public void Test_Simple_1() { var path = Filepath.Parse("a/b/c.tar.gz"); Assert.IsTrue(path.Prefix is PathPrefix.Empty); Assert.IsFalse(path.Absolute); Assert.AreEqual(3, path.Items.Length); Assert.AreEqual("a", path.Items[0]); Assert.AreEqual("b", path.Items[1]); Assert.AreEqual("c.tar.gz", path.Items[2]); Assert.AreEqual("a/b/c.tar.gz", path.ToString("/")); }
public void Test_TraditionalDos_2() { Action <string> test_ = pathStr => { var path = Filepath.Parse(pathStr); Assert.IsTrue(path.Absolute); Assert.AreEqual(1, path.Items.Length); }; test_(@"C:\a"); test_(@"C:\a\"); }
public void Test_Combine_2() { var basepath = Filepath.Parse("relative/dir"); var other = Filepath.Parse("/abs/file.txt"); var rv = basepath.Combine(other.Items); Assert.IsInstanceOfType(rv.Prefix, typeof(PathPrefix.None)); Assert.IsFalse(basepath.IsAbsolute); Assert.AreEqual(4, rv.Items.Count); Assert.AreEqual("relative", rv.Items[0]); Assert.AreEqual("file.txt", rv.Items[3]); }
public void Test_Simple_Absolute_2() { Action <string> test_ = pathStr => { var path = Filepath.Parse(pathStr); Assert.IsTrue(path.Prefix is PathPrefix.Empty); Assert.IsTrue(path.Absolute); Assert.AreEqual(3, path.Items.Length); Assert.AreEqual("/usr/local/bin", path.ToString("/")); }; test_("/usr/local/bin"); test_("/usr/local/bin/"); // ends with "/" }
public void Test_DosDevice_2_UNC() { var path = Filepath.Parse(@"\\.\UNC\foo\bar\baz"); var prefix = path.Prefix as DosDevice; Assert.IsNotNull(prefix); Assert.IsTrue(prefix !.IsUnc); Assert.AreEqual("foo", prefix !.Server); Assert.AreEqual("bar", prefix !.Share); Assert.AreEqual(@"foo\bar", prefix.Volume); Assert.AreEqual(1, path.Items.Length); Assert.AreEqual("baz", path.Items[0]); }