private void DoNodesForFolder(string cat, string sub) { string currPath = path + cat + "\\" + sub + "\\"; string[] fl = Directory.GetFiles(currPath, "*.*", SearchOption.AllDirectories) .Where(s => s.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase)).ToArray(); foreach (string f in fl) { string nm = f.Substring(path.Length + 2 + cat.Length + sub.Length); nm = nm.Substring(0, nm.Length - 4); string nameForFile = f.Substring(0, f.Length - 4); string txtFile = nameForFile + ".txt"; string fullTextFile = nameForFile + " Full Text.txt"; string[] contents; if (File.Exists(txtFile)) { contents = File.ReadLines(txtFile).ToArray(); } else { File.WriteAllText(txtFile, nm); contents = new string[1]; contents[0] = nm; } string ft = ""; if (File.Exists(fullTextFile)) { string[] ftLines = File.ReadLines(fullTextFile).ToArray(); foreach (string s in ftLines) { ft += s + " "; } ft = ft.Trim(); } List <string> goodTags = new List <string>(); for (int i = 1; i < contents.Length; i++) { if (contents[i] != "") { goodTags.Add(contents[i]); } } files.Add(new DataFile(contents[0], goodTags.ToArray(), cat, sub, nm, ft)); } }
public void TestAppendText() { string filename = Util.CreateNewFile(longPathDirectory); try { using (var sw = File.AppendText(filename)) { sw.WriteLine("end of file"); } var lines = File.ReadLines(filename); Assert.IsTrue(new[] { "beginning of file", "end of file" }.SequenceEqual(lines)); } finally { File.Delete(filename); } }
public static IEnumerable <string> ReadLines(string path, Encoding encoding) { return(File.ReadLines(path, encoding)); }
public static IEnumerable <string> ReadLines(string path) { return(File.ReadLines(path)); }