You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

137 lines
8.1 KiB

  1. /* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. * THE SOFTWARE.
  20. */
  21. using System;
  22. using System.Collections.Generic;
  23. using System.Diagnostics.CodeAnalysis;
  24. using System.IO;
  25. using System.Security;
  26. namespace Alphaleonis.Win32.Filesystem
  27. {
  28. partial class DirectoryInfo
  29. {
  30. #region .NET
  31. /// <summary>Returns an enumerable collection of file system information in the current directory.</summary>
  32. /// <returns>An enumerable collection of file system information in the current directory. </returns>
  33. /// <exception cref="ArgumentException"/>
  34. /// <exception cref="ArgumentNullException"/>
  35. /// <exception cref="DirectoryNotFoundException"/>
  36. /// <exception cref="IOException"/>
  37. /// <exception cref="NotSupportedException"/>
  38. /// <exception cref="UnauthorizedAccessException"/>
  39. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
  40. [SecurityCritical]
  41. public IEnumerable<FileSystemInfo> EnumerateFileSystemInfos()
  42. {
  43. return Directory.EnumerateFileSystemEntryInfosCore<FileSystemInfo>(Transaction, LongFullName, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.LongFullPath);
  44. }
  45. /// <summary>Returns an enumerable collection of file system information that matches a specified search pattern.</summary>
  46. /// <returns>An enumerable collection of file system information objects that matches <paramref name="searchPattern"/>.</returns>
  47. /// <exception cref="ArgumentException"/>
  48. /// <exception cref="ArgumentNullException"/>
  49. /// <exception cref="DirectoryNotFoundException"/>
  50. /// <exception cref="IOException"/>
  51. /// <exception cref="NotSupportedException"/>
  52. /// <exception cref="UnauthorizedAccessException"/>
  53. /// <param name="searchPattern">
  54. /// The search string to match against the names of directories in path.
  55. /// This parameter can contain a combination of valid literal path and wildcard
  56. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  57. /// </param>
  58. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
  59. [SecurityCritical]
  60. public IEnumerable<FileSystemInfo> EnumerateFileSystemInfos(string searchPattern)
  61. {
  62. return Directory.EnumerateFileSystemEntryInfosCore<FileSystemInfo>(Transaction, LongFullName, searchPattern, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.LongFullPath);
  63. }
  64. /// <summary>Returns an enumerable collection of file system information that matches a specified search pattern and search subdirectory option.</summary>
  65. /// <returns>An enumerable collection of file system information objects that matches <paramref name="searchPattern"/> and <paramref name="searchOption"/>.</returns>
  66. /// <exception cref="ArgumentException"/>
  67. /// <exception cref="ArgumentNullException"/>
  68. /// <exception cref="DirectoryNotFoundException"/>
  69. /// <exception cref="IOException"/>
  70. /// <exception cref="NotSupportedException"/>
  71. /// <exception cref="UnauthorizedAccessException"/>
  72. /// <param name="searchPattern">
  73. /// The search string to match against the names of directories in path.
  74. /// This parameter can contain a combination of valid literal path and wildcard
  75. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  76. /// </param>
  77. /// <param name="searchOption">
  78. /// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
  79. /// should include only the current directory or should include all subdirectories.
  80. /// </param>
  81. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
  82. [SecurityCritical]
  83. public IEnumerable<FileSystemInfo> EnumerateFileSystemInfos(string searchPattern, SearchOption searchOption)
  84. {
  85. var options = DirectoryEnumerationOptions.FilesAndFolders | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);
  86. return Directory.EnumerateFileSystemEntryInfosCore<FileSystemInfo>(Transaction, LongFullName, searchPattern, options, PathFormat.LongFullPath);
  87. }
  88. #endregion // .NET
  89. /// <summary>[AlphaFS] Returns an enumerable collection of file system information in the current directory.</summary>
  90. /// <returns>An enumerable collection of file system information in the current directory. </returns>
  91. /// <exception cref="ArgumentException"/>
  92. /// <exception cref="ArgumentNullException"/>
  93. /// <exception cref="DirectoryNotFoundException"/>
  94. /// <exception cref="IOException"/>
  95. /// <exception cref="NotSupportedException"/>
  96. /// <exception cref="UnauthorizedAccessException"/>
  97. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  98. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
  99. [SecurityCritical]
  100. public IEnumerable<FileSystemInfo> EnumerateFileSystemInfos(DirectoryEnumerationOptions options)
  101. {
  102. return Directory.EnumerateFileSystemEntryInfosCore<FileSystemInfo>(Transaction, LongFullName, Path.WildcardStarMatchAll, options, PathFormat.LongFullPath);
  103. }
  104. /// <summary>[AlphaFS] Returns an enumerable collection of file system information that matches a specified search pattern.</summary>
  105. /// <returns>An enumerable collection of file system information objects that matches <paramref name="searchPattern"/>.</returns>
  106. /// <exception cref="ArgumentException"/>
  107. /// <exception cref="ArgumentNullException"/>
  108. /// <exception cref="DirectoryNotFoundException"/>
  109. /// <exception cref="IOException"/>
  110. /// <exception cref="NotSupportedException"/>
  111. /// <exception cref="UnauthorizedAccessException"/>
  112. /// <param name="searchPattern">
  113. /// The search string to match against the names of directories in path.
  114. /// This parameter can contain a combination of valid literal path and wildcard
  115. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  116. /// </param>
  117. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  118. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
  119. [SecurityCritical]
  120. public IEnumerable<FileSystemInfo> EnumerateFileSystemInfos(string searchPattern, DirectoryEnumerationOptions options)
  121. {
  122. return Directory.EnumerateFileSystemEntryInfosCore<FileSystemInfo>(Transaction, LongFullName, searchPattern, options, PathFormat.LongFullPath);
  123. }
  124. }
  125. }