Folder Contents


SUBMITTED BY: mokkacyan

DATE: April 16, 2016, 10:46 a.m.

FORMAT: Text only

SIZE: 3.5 kB

HITS: 731

  1. using System;
  2. using System.IO;
  3. using System.ComponentModel;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace FolderContents
  9. {
  10. public class FolderContents : INotifyPropertyChanged
  11. {
  12. private string fldrPath = "";
  13. private string fldrPath2 = "";
  14. private string[] fldrFiles;
  15. private string allowedExtensions = "";
  16. public event PropertyChangedEventHandler PropertyChanged;
  17. private void NotifyPropertyChanged(String info)
  18. {
  19. if (PropertyChanged != null)
  20. {
  21. PropertyChanged(this, new PropertyChangedEventArgs(info));
  22. }
  23. }
  24. public string FolderPath
  25. {
  26. get
  27. {
  28. return this.fldrPath;
  29. }
  30. set
  31. {
  32. this.fldrPath = value;
  33. NotifyPropertyChanged("FolderPath");
  34. RefreshFolderFiles();
  35. }
  36. }
  37. public string FolderPath2
  38. {
  39. get
  40. {
  41. return this.fldrPath2;
  42. }
  43. set
  44. {
  45. this.fldrPath2 = value;
  46. NotifyPropertyChanged("FolderPath2");
  47. RefreshFolderFiles();
  48. }
  49. }
  50. public string AllowedExtensions
  51. {
  52. get
  53. {
  54. return this.allowedExtensions;
  55. }
  56. set
  57. {
  58. this.allowedExtensions = value;
  59. NotifyPropertyChanged("AllowedExtensions");
  60. RefreshFolderFiles();
  61. }
  62. }
  63. public string[] FolderFiles
  64. {
  65. get
  66. {
  67. return this.fldrFiles;
  68. }
  69. set
  70. {
  71. }
  72. }
  73. public void RefreshFolderFiles()
  74. {
  75. List<string> files = new List<string>();
  76. if (Directory.Exists(this.fldrPath))
  77. {
  78. if (this.allowedExtensions == "")
  79. {
  80. files.AddRange(Directory.GetFiles(this.fldrPath));
  81. } else
  82. {
  83. string[] filters = this.allowedExtensions.Split(new Char[] { ';' });
  84. foreach (string filter in filters)
  85. {
  86. files.AddRange(Directory.GetFiles(this.fldrPath, filter));
  87. }
  88. }
  89. }
  90. if (Directory.Exists(this.fldrPath2))
  91. {
  92. if (this.allowedExtensions == "")
  93. {
  94. files.AddRange(Directory.GetFiles(this.fldrPath2));
  95. }
  96. else
  97. {
  98. string[] filters = this.allowedExtensions.Split(new Char[] { ';' });
  99. foreach (string filter in filters)
  100. {
  101. files.AddRange(Directory.GetFiles(this.fldrPath2, filter));
  102. }
  103. }
  104. }
  105. List<string> orderedfiles = new List<string>();
  106. orderedfiles.AddRange(files.OrderByDescending(d => new FileInfo(d).CreationTime));
  107. this.fldrFiles = orderedfiles.ToArray();
  108. NotifyPropertyChanged("FolderFiles");
  109. }
  110. }
  111. }

comments powered by Disqus