Advertisement
RupertAvery

Generate filelist.txt for Loadiine

Oct 15th, 2017
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4.  
  5. namespace FileLister {
  6.  
  7. public class Program {
  8. public static void Main(string[] args) {
  9. buildFileList(".", "content", "filelist.txt");
  10. }
  11.  
  12. public static void buildFileList(string basePath, string targetPath, string filename) {
  13. var contentFolder = basePath + "\\" + targetPath;
  14. if(Directory.Exists(contentFolder)){
  15. using(var fs = new FileStream(basePath + "\\" + filename, FileMode.Create)){
  16. using(var sw = new StreamWriter(fs)){
  17. sw.Write(readFileListRecursive(contentFolder));
  18. }
  19. }
  20. }
  21. }
  22.  
  23. //TODO make it more generic
  24. private static string readFileListRecursive(string contentFolder) {
  25. if(Directory.Exists(contentFolder)){
  26. var sb = new StringBuilder();
  27. foreach(var f in Directory.GetDirectories(contentFolder)){
  28. sb.Append("?" + Path.GetFileName(f) + "\n");
  29. sb.Append(readFileListRecursive(f));
  30. sb.Append("?..\n");
  31. }
  32. foreach(var f in Directory.GetFiles(contentFolder)){
  33. sb.Append(Path.GetFileName(f) + "\n");
  34. }
  35. return sb.ToString();
  36. }else{
  37. return "";
  38. }
  39. }
  40.  
  41. }
  42.  
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement