Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

Directory.EnumerateDirectories.cs 32 KiB

7 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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.IO;
  24. using System.Security;
  25. using SearchOption = System.IO.SearchOption;
  26. namespace Alphaleonis.Win32.Filesystem
  27. {
  28. partial class Directory
  29. {
  30. #region .NET
  31. /// <summary>Returns an enumerable collection of directory names in a specified <paramref name="path"/>.</summary>
  32. /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/>.</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. /// <param name="path">The directory to search.</param>
  40. [SecurityCritical]
  41. public static IEnumerable<string> EnumerateDirectories(string path)
  42. {
  43. return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.Folders, PathFormat.RelativePath);
  44. }
  45. /// <summary>Returns an enumerable collection of directory names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>.</summary>
  46. /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/> and that match the specified <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="path">The directory to search.</param>
  54. /// <param name="searchPattern">
  55. /// The search string to match against the names of directories in <paramref name="path"/>.
  56. /// This parameter can contain a combination of valid literal path and wildcard
  57. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  58. /// </param>
  59. [SecurityCritical]
  60. public static IEnumerable<string> EnumerateDirectories(string path, string searchPattern)
  61. {
  62. return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, DirectoryEnumerationOptions.Folders, PathFormat.RelativePath);
  63. }
  64. /// <summary>Returns an enumerable collection of directory names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>, and optionally searches subdirectories.</summary>
  65. /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/> and that match the specified <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="path">The directory to search.</param>
  73. /// <param name="searchPattern">
  74. /// The search string to match against the names of directories in <paramref name="path"/>.
  75. /// This parameter can contain a combination of valid literal path and wildcard
  76. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  77. /// </param>
  78. /// <param name="searchOption">
  79. /// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
  80. /// should include only the current directory or should include all subdirectories.
  81. /// </param>
  82. [SecurityCritical]
  83. public static IEnumerable<string> EnumerateDirectories(string path, string searchPattern, SearchOption searchOption)
  84. {
  85. var options = DirectoryEnumerationOptions.Folders | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);
  86. return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, options, PathFormat.RelativePath);
  87. }
  88. #endregion // .NET
  89. /// <summary>[AlphaFS] Returns an enumerable collection of directory names in a specified <paramref name="path"/>.</summary>
  90. /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/>.</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="path">The directory to search.</param>
  98. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  99. [SecurityCritical]
  100. public static IEnumerable<string> EnumerateDirectories(string path, PathFormat pathFormat)
  101. {
  102. return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.Folders, pathFormat);
  103. }
  104. /// <summary>[AlphaFS] Returns an enumerable collection of directory names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>.</summary>
  105. /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/> and that match the specified <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="path">The directory to search.</param>
  113. /// <param name="searchPattern">
  114. /// The search string to match against the names of directories in <paramref name="path"/>.
  115. /// This parameter can contain a combination of valid literal path and wildcard
  116. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  117. /// </param>
  118. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  119. [SecurityCritical]
  120. public static IEnumerable<string> EnumerateDirectories(string path, string searchPattern, PathFormat pathFormat)
  121. {
  122. return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, DirectoryEnumerationOptions.Folders, pathFormat);
  123. }
  124. /// <summary>[AlphaFS] Returns an enumerable collection of directory names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>, and optionally searches subdirectories.</summary>
  125. /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/> and <paramref name="searchOption"/>.</returns>
  126. /// <exception cref="ArgumentException"/>
  127. /// <exception cref="ArgumentNullException"/>
  128. /// <exception cref="DirectoryNotFoundException"/>
  129. /// <exception cref="IOException"/>
  130. /// <exception cref="NotSupportedException"/>
  131. /// <exception cref="UnauthorizedAccessException"/>
  132. /// <param name="path">The directory to search.</param>
  133. /// <param name="searchPattern">
  134. /// The search string to match against the names of directories in <paramref name="path"/>.
  135. /// This parameter can contain a combination of valid literal path and wildcard
  136. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  137. /// </param>
  138. /// <param name="searchOption">
  139. /// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
  140. /// should include only the current directory or should include all subdirectories.
  141. /// </param>
  142. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  143. [SecurityCritical]
  144. public static IEnumerable<string> EnumerateDirectories(string path, string searchPattern, SearchOption searchOption, PathFormat pathFormat)
  145. {
  146. var options = DirectoryEnumerationOptions.Folders | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);
  147. return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, options, pathFormat);
  148. }
  149. /// <summary>[AlphaFS] Returns an enumerable collection of directory names in a specified <paramref name="path"/>.</summary>
  150. /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/>.</returns>
  151. /// <exception cref="ArgumentException"/>
  152. /// <exception cref="ArgumentNullException"/>
  153. /// <exception cref="DirectoryNotFoundException"/>
  154. /// <exception cref="IOException"/>
  155. /// <exception cref="NotSupportedException"/>
  156. /// <exception cref="UnauthorizedAccessException"/>
  157. /// <param name="path">The directory to search.</param>
  158. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  159. [SecurityCritical]
  160. public static IEnumerable<string> EnumerateDirectories(string path, DirectoryEnumerationOptions options)
  161. {
  162. // Adhere to the method name.
  163. options &= ~DirectoryEnumerationOptions.Files; // Remove enumeration of files.
  164. options |= DirectoryEnumerationOptions.Folders; // Add enumeration of directories.
  165. return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, options, PathFormat.RelativePath);
  166. }
  167. /// <summary>[AlphaFS] Returns an enumerable collection of directory names in a specified <paramref name="path"/>.</summary>
  168. /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/>.</returns>
  169. /// <exception cref="ArgumentException"/>
  170. /// <exception cref="ArgumentNullException"/>
  171. /// <exception cref="DirectoryNotFoundException"/>
  172. /// <exception cref="IOException"/>
  173. /// <exception cref="NotSupportedException"/>
  174. /// <exception cref="UnauthorizedAccessException"/>
  175. /// <param name="path">The directory to search.</param>
  176. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  177. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  178. [SecurityCritical]
  179. public static IEnumerable<string> EnumerateDirectories(string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
  180. {
  181. // Adhere to the method name.
  182. options &= ~DirectoryEnumerationOptions.Files;
  183. options |= DirectoryEnumerationOptions.Folders;
  184. return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, options, pathFormat);
  185. }
  186. /// <summary>[AlphaFS] Returns an enumerable collection of directory names in a specified <paramref name="path"/>.</summary>
  187. /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/>.</returns>
  188. /// <exception cref="ArgumentException"/>
  189. /// <exception cref="ArgumentNullException"/>
  190. /// <exception cref="DirectoryNotFoundException"/>
  191. /// <exception cref="IOException"/>
  192. /// <exception cref="NotSupportedException"/>
  193. /// <exception cref="UnauthorizedAccessException"/>
  194. /// <param name="path">The directory to search.</param>
  195. /// <param name="searchPattern">
  196. /// The search string to match against the names of directories in <paramref name="path"/>.
  197. /// This parameter can contain a combination of valid literal path and wildcard
  198. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  199. /// </param>
  200. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  201. [SecurityCritical]
  202. public static IEnumerable<string> EnumerateDirectories(string path, string searchPattern, DirectoryEnumerationOptions options)
  203. {
  204. // Adhere to the method name.
  205. options &= ~DirectoryEnumerationOptions.Files;
  206. options |= DirectoryEnumerationOptions.Folders;
  207. return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, options, PathFormat.RelativePath);
  208. }
  209. /// <summary>[AlphaFS] Returns an enumerable collection of directory names in a specified <paramref name="path"/>.</summary>
  210. /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/>.</returns>
  211. /// <exception cref="ArgumentException"/>
  212. /// <exception cref="ArgumentNullException"/>
  213. /// <exception cref="DirectoryNotFoundException"/>
  214. /// <exception cref="IOException"/>
  215. /// <exception cref="NotSupportedException"/>
  216. /// <exception cref="UnauthorizedAccessException"/>
  217. /// <param name="path">The directory to search.</param>
  218. /// <param name="searchPattern">
  219. /// The search string to match against the names of directories in <paramref name="path"/>.
  220. /// This parameter can contain a combination of valid literal path and wildcard
  221. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  222. /// </param>
  223. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  224. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  225. [SecurityCritical]
  226. public static IEnumerable<string> EnumerateDirectories(string path, string searchPattern, DirectoryEnumerationOptions options, PathFormat pathFormat)
  227. {
  228. // Adhere to the method name.
  229. options &= ~DirectoryEnumerationOptions.Files;
  230. options |= DirectoryEnumerationOptions.Folders;
  231. return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, options, pathFormat);
  232. }
  233. #region Transactional
  234. /// <summary>[AlphaFS] Returns an enumerable collection of directory instances in a specified <paramref name="path"/>.</summary>
  235. /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/>.</returns>
  236. /// <exception cref="ArgumentException"/>
  237. /// <exception cref="ArgumentNullException"/>
  238. /// <exception cref="DirectoryNotFoundException"/>
  239. /// <exception cref="IOException"/>
  240. /// <exception cref="NotSupportedException"/>
  241. /// <exception cref="UnauthorizedAccessException"/>
  242. /// <param name="transaction">The transaction.</param>
  243. /// <param name="path">The directory to search.</param>
  244. [SecurityCritical]
  245. public static IEnumerable<string> EnumerateDirectoriesTransacted(KernelTransaction transaction, string path)
  246. {
  247. return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.Folders, PathFormat.RelativePath);
  248. }
  249. /// <summary>[AlphaFS] Returns an enumerable collection of directory instances that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>.</summary>
  250. /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/>.</returns>
  251. /// <exception cref="ArgumentException"/>
  252. /// <exception cref="ArgumentNullException"/>
  253. /// <exception cref="DirectoryNotFoundException"/>
  254. /// <exception cref="IOException"/>
  255. /// <exception cref="NotSupportedException"/>
  256. /// <exception cref="UnauthorizedAccessException"/>
  257. /// <param name="transaction">The transaction.</param>
  258. /// <param name="path">The directory to search.</param>
  259. /// <param name="searchPattern">
  260. /// The search string to match against the names of directories in <paramref name="path"/>.
  261. /// This parameter can contain a combination of valid literal path and wildcard
  262. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  263. /// </param>
  264. [SecurityCritical]
  265. public static IEnumerable<string> EnumerateDirectoriesTransacted(KernelTransaction transaction, string path, string searchPattern)
  266. {
  267. return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, DirectoryEnumerationOptions.Folders, PathFormat.RelativePath);
  268. }
  269. /// <summary>[AlphaFS] Returns an enumerable collection of directory names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>, and optionally searches subdirectories.</summary>
  270. /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/> and <paramref name="searchOption"/>.</returns>
  271. /// <exception cref="ArgumentException"/>
  272. /// <exception cref="ArgumentNullException"/>
  273. /// <exception cref="DirectoryNotFoundException"/>
  274. /// <exception cref="IOException"/>
  275. /// <exception cref="NotSupportedException"/>
  276. /// <exception cref="UnauthorizedAccessException"/>
  277. /// <param name="transaction">The transaction.</param>
  278. /// <param name="path">The directory to search.</param>
  279. /// <param name="searchPattern">
  280. /// The search string to match against the names of directories in <paramref name="path"/>.
  281. /// This parameter can contain a combination of valid literal path and wildcard
  282. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  283. /// </param>
  284. /// <param name="searchOption">
  285. /// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
  286. /// should include only the current directory or should include all subdirectories.
  287. /// </param>
  288. [SecurityCritical]
  289. public static IEnumerable<string> EnumerateDirectoriesTransacted(KernelTransaction transaction, string path, string searchPattern, SearchOption searchOption)
  290. {
  291. var options = DirectoryEnumerationOptions.Folders | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);
  292. return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, options, PathFormat.RelativePath);
  293. }
  294. /// <summary>[AlphaFS] Returns an enumerable collection of directory instances in a specified <paramref name="path"/>.</summary>
  295. /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/>.</returns>
  296. /// <exception cref="ArgumentException"/>
  297. /// <exception cref="ArgumentNullException"/>
  298. /// <exception cref="DirectoryNotFoundException"/>
  299. /// <exception cref="IOException"/>
  300. /// <exception cref="NotSupportedException"/>
  301. /// <exception cref="UnauthorizedAccessException"/>
  302. /// <param name="transaction">The transaction.</param>
  303. /// <param name="path">The directory to search.</param>
  304. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  305. [SecurityCritical]
  306. public static IEnumerable<string> EnumerateDirectoriesTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
  307. {
  308. return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.Folders, pathFormat);
  309. }
  310. /// <summary>[AlphaFS] Returns an enumerable collection of directory instances that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>.</summary>
  311. /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/>.</returns>
  312. /// <exception cref="ArgumentException"/>
  313. /// <exception cref="ArgumentNullException"/>
  314. /// <exception cref="DirectoryNotFoundException"/>
  315. /// <exception cref="IOException"/>
  316. /// <exception cref="NotSupportedException"/>
  317. /// <exception cref="UnauthorizedAccessException"/>
  318. /// <param name="transaction">The transaction.</param>
  319. /// <param name="path">The directory to search.</param>
  320. /// <param name="searchPattern">
  321. /// The search string to match against the names of directories in <paramref name="path"/>.
  322. /// This parameter can contain a combination of valid literal path and wildcard
  323. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  324. /// </param>
  325. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  326. [SecurityCritical]
  327. public static IEnumerable<string> EnumerateDirectoriesTransacted(KernelTransaction transaction, string path, string searchPattern, PathFormat pathFormat)
  328. {
  329. return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, DirectoryEnumerationOptions.Folders, pathFormat);
  330. }
  331. /// <summary>[AlphaFS] Returns an enumerable collection of directory names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>, and optionally searches subdirectories.</summary>
  332. /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/> and <paramref name="searchOption"/>.</returns>
  333. /// <exception cref="ArgumentException"/>
  334. /// <exception cref="ArgumentNullException"/>
  335. /// <exception cref="DirectoryNotFoundException"/>
  336. /// <exception cref="IOException"/>
  337. /// <exception cref="NotSupportedException"/>
  338. /// <exception cref="UnauthorizedAccessException"/>
  339. /// <param name="transaction">The transaction.</param>
  340. /// <param name="path">The directory to search.</param>
  341. /// <param name="searchPattern">
  342. /// The search string to match against the names of directories in <paramref name="path"/>.
  343. /// This parameter can contain a combination of valid literal path and wildcard
  344. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  345. /// </param>
  346. /// <param name="searchOption">
  347. /// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
  348. /// should include only the current directory or should include all subdirectories.
  349. /// </param>
  350. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  351. [SecurityCritical]
  352. public static IEnumerable<string> EnumerateDirectoriesTransacted(KernelTransaction transaction, string path, string searchPattern, SearchOption searchOption, PathFormat pathFormat)
  353. {
  354. var options = DirectoryEnumerationOptions.Folders | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);
  355. return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, options, pathFormat);
  356. }
  357. /// <summary>[AlphaFS] Returns an enumerable collection of directory instances in a specified <paramref name="path"/>.</summary>
  358. /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/>.</returns>
  359. /// <exception cref="ArgumentException"/>
  360. /// <exception cref="ArgumentNullException"/>
  361. /// <exception cref="DirectoryNotFoundException"/>
  362. /// <exception cref="IOException"/>
  363. /// <exception cref="NotSupportedException"/>
  364. /// <exception cref="UnauthorizedAccessException"/>
  365. /// <param name="transaction">The transaction.</param>
  366. /// <param name="path">The directory to search.</param>
  367. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  368. [SecurityCritical]
  369. public static IEnumerable<string> EnumerateDirectoriesTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options)
  370. {
  371. // Adhere to the method name.
  372. options &= ~DirectoryEnumerationOptions.Files;
  373. options |= DirectoryEnumerationOptions.Folders;
  374. return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, options, PathFormat.RelativePath);
  375. }
  376. /// <summary>[AlphaFS] Returns an enumerable collection of directory instances in a specified <paramref name="path"/>.</summary>
  377. /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/>.</returns>
  378. /// <exception cref="ArgumentException"/>
  379. /// <exception cref="ArgumentNullException"/>
  380. /// <exception cref="DirectoryNotFoundException"/>
  381. /// <exception cref="IOException"/>
  382. /// <exception cref="NotSupportedException"/>
  383. /// <exception cref="UnauthorizedAccessException"/>
  384. /// <param name="transaction">The transaction.</param>
  385. /// <param name="path">The directory to search.</param>
  386. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  387. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  388. [SecurityCritical]
  389. public static IEnumerable<string> EnumerateDirectoriesTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
  390. {
  391. // Adhere to the method name.
  392. options &= ~DirectoryEnumerationOptions.Files;
  393. options |= DirectoryEnumerationOptions.Folders;
  394. return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, options, pathFormat);
  395. }
  396. /// <summary>[AlphaFS] Returns an enumerable collection of directory instances that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>.</summary>
  397. /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/>.</returns>
  398. /// <exception cref="ArgumentException"/>
  399. /// <exception cref="ArgumentNullException"/>
  400. /// <exception cref="DirectoryNotFoundException"/>
  401. /// <exception cref="IOException"/>
  402. /// <exception cref="NotSupportedException"/>
  403. /// <exception cref="UnauthorizedAccessException"/>
  404. /// <param name="transaction">The transaction.</param>
  405. /// <param name="path">The directory to search.</param>
  406. /// <param name="searchPattern">
  407. /// The search string to match against the names of directories in <paramref name="path"/>.
  408. /// This parameter can contain a combination of valid literal path and wildcard
  409. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  410. /// </param>
  411. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  412. [SecurityCritical]
  413. public static IEnumerable<string> EnumerateDirectoriesTransacted(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options)
  414. {
  415. // Adhere to the method name.
  416. options &= ~DirectoryEnumerationOptions.Files;
  417. options |= DirectoryEnumerationOptions.Folders;
  418. return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, options, PathFormat.RelativePath);
  419. }
  420. /// <summary>[AlphaFS] Returns an enumerable collection of directory instances that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>.</summary>
  421. /// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/>.</returns>
  422. /// <exception cref="ArgumentException"/>
  423. /// <exception cref="ArgumentNullException"/>
  424. /// <exception cref="DirectoryNotFoundException"/>
  425. /// <exception cref="IOException"/>
  426. /// <exception cref="NotSupportedException"/>
  427. /// <exception cref="UnauthorizedAccessException"/>
  428. /// <param name="transaction">The transaction.</param>
  429. /// <param name="path">The directory to search.</param>
  430. /// <param name="searchPattern">
  431. /// The search string to match against the names of directories in <paramref name="path"/>.
  432. /// This parameter can contain a combination of valid literal path and wildcard
  433. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  434. /// </param>
  435. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  436. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  437. [SecurityCritical]
  438. public static IEnumerable<string> EnumerateDirectoriesTransacted(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options, PathFormat pathFormat)
  439. {
  440. // Adhere to the method name.
  441. options &= ~DirectoryEnumerationOptions.Files;
  442. options |= DirectoryEnumerationOptions.Folders;
  443. return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, options, pathFormat);
  444. }
  445. #endregion // Transactional
  446. }
  447. }