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.
 
 

503 lines
32 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.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 file names in a specified <paramref name="path"/>.</summary>
  32. /// <returns>An enumerable collection of the full names (including paths) for the files 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> EnumerateFiles(string path)
  42. {
  43. return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.Files, PathFormat.RelativePath);
  44. }
  45. /// <summary>Returns an enumerable collection of file names in a specified <paramref name="path"/>.</summary>
  46. /// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by <paramref name="path"/> and that match the <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> EnumerateFiles(string path, string searchPattern)
  61. {
  62. return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, DirectoryEnumerationOptions.Files, PathFormat.RelativePath);
  63. }
  64. /// <summary>Returns an enumerable collection of file 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 files 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> EnumerateFiles(string path, string searchPattern, SearchOption searchOption)
  84. {
  85. var options = DirectoryEnumerationOptions.Files | ((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 file names in a specified <paramref name="path"/>.</summary>
  90. /// <returns>An enumerable collection of the full names (including paths) for the files 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> EnumerateFiles(string path, PathFormat pathFormat)
  101. {
  102. return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.Files, pathFormat);
  103. }
  104. /// <summary>[AlphaFS] Returns an enumerable collection of file names in a specified <paramref name="path"/>.</summary>
  105. /// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by <paramref name="path"/> and that match the <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> EnumerateFiles(string path, string searchPattern, PathFormat pathFormat)
  121. {
  122. return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, DirectoryEnumerationOptions.Files, pathFormat);
  123. }
  124. /// <summary>[AlphaFS] Returns an enumerable collection of file 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 files 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> EnumerateFiles(string path, string searchPattern, SearchOption searchOption, PathFormat pathFormat)
  145. {
  146. var options = DirectoryEnumerationOptions.Files | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);
  147. return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, options, pathFormat);
  148. }
  149. /// <summary>[AlphaFS] Returns an enumerable collection of file names in a specified <paramref name="path"/>.</summary>
  150. /// <returns>An enumerable collection of the full names (including paths) for the files 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> EnumerateFiles(string path, DirectoryEnumerationOptions options)
  161. {
  162. // Adhere to the method name.
  163. options &= ~DirectoryEnumerationOptions.Folders; // Remove enumeration of directories.
  164. options |= DirectoryEnumerationOptions.Files; // Add enumeration of files.
  165. return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, options, PathFormat.RelativePath);
  166. }
  167. /// <summary>[AlphaFS] Returns an enumerable collection of file names in a specified <paramref name="path"/>.</summary>
  168. /// <returns>An enumerable collection of the full names (including paths) for the files 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> EnumerateFiles(string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
  180. {
  181. // Adhere to the method name.
  182. options &= ~DirectoryEnumerationOptions.Folders;
  183. options |= DirectoryEnumerationOptions.Files;
  184. return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, options, pathFormat);
  185. }
  186. /// <summary>[AlphaFS] Returns an enumerable collection of file names in a specified <paramref name="path"/>.</summary>
  187. /// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by <paramref name="path"/> and that match the <paramref name="searchPattern"/>.</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> EnumerateFiles(string path, string searchPattern, DirectoryEnumerationOptions options)
  203. {
  204. // Adhere to the method name.
  205. options &= ~DirectoryEnumerationOptions.Folders;
  206. options |= DirectoryEnumerationOptions.Files;
  207. return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, options, PathFormat.RelativePath);
  208. }
  209. /// <summary>[AlphaFS] Returns an enumerable collection of file names in a specified <paramref name="path"/>.</summary>
  210. /// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by <paramref name="path"/> and that match the <paramref name="searchPattern"/>.</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> EnumerateFiles(string path, string searchPattern, DirectoryEnumerationOptions options, PathFormat pathFormat)
  227. {
  228. // Adhere to the method name.
  229. options &= ~DirectoryEnumerationOptions.Folders;
  230. options |= DirectoryEnumerationOptions.Files;
  231. return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, options, pathFormat);
  232. }
  233. #region Transactional
  234. /// <summary>[AlphaFS] Returns an enumerable collection of file names in a specified <paramref name="path"/>.</summary>
  235. /// <returns>An enumerable collection of the full names (including paths) for the files 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> EnumerateFilesTransacted(KernelTransaction transaction, string path)
  246. {
  247. return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.Files, PathFormat.RelativePath);
  248. }
  249. /// <summary>[AlphaFS] Returns an enumerable collection of file 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 files in the directory specified by <paramref name="path"/> and that match the <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> EnumerateFilesTransacted(KernelTransaction transaction, string path, string searchPattern)
  266. {
  267. return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, DirectoryEnumerationOptions.Files, PathFormat.RelativePath);
  268. }
  269. /// <summary>[AlphaFS] Returns an enumerable collection of file instances instances 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 files 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> EnumerateFilesTransacted(KernelTransaction transaction, string path, string searchPattern, SearchOption searchOption)
  290. {
  291. var options = DirectoryEnumerationOptions.Files | ((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 file names in a specified <paramref name="path"/>.</summary>
  295. /// <returns>An enumerable collection of the full names (including paths) for the files 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> EnumerateFilesTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
  307. {
  308. return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.Files, pathFormat);
  309. }
  310. /// <summary>[AlphaFS] Returns an enumerable collection of file 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 files in the directory specified by <paramref name="path"/> and that match the <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> EnumerateFilesTransacted(KernelTransaction transaction, string path, string searchPattern, PathFormat pathFormat)
  328. {
  329. return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, DirectoryEnumerationOptions.Files, pathFormat);
  330. }
  331. /// <summary>[AlphaFS] Returns an enumerable collection of file instances instances 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 files 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> EnumerateFilesTransacted(KernelTransaction transaction, string path, string searchPattern, SearchOption searchOption, PathFormat pathFormat)
  353. {
  354. var options = DirectoryEnumerationOptions.Files | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);
  355. return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, options, pathFormat);
  356. }
  357. /// <summary>[AlphaFS] Returns an enumerable collection of file names in a specified <paramref name="path"/>.</summary>
  358. /// <returns>An enumerable collection of the full names (including paths) for the files 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> EnumerateFilesTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options)
  370. {
  371. // Adhere to the method name.
  372. options &= ~DirectoryEnumerationOptions.Folders;
  373. options |= DirectoryEnumerationOptions.Files;
  374. return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, options, PathFormat.RelativePath);
  375. }
  376. /// <summary>[AlphaFS] Returns an enumerable collection of file names in a specified <paramref name="path"/>.</summary>
  377. /// <returns>An enumerable collection of the full names (including paths) for the files 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> EnumerateFilesTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
  390. {
  391. // Adhere to the method name.
  392. options &= ~DirectoryEnumerationOptions.Folders;
  393. options |= DirectoryEnumerationOptions.Files;
  394. return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, options, pathFormat);
  395. }
  396. /// <summary>[AlphaFS] Returns an enumerable collection of file 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 files in the directory specified by <paramref name="path"/> and that match the <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> EnumerateFilesTransacted(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options)
  414. {
  415. // Adhere to the method name.
  416. options &= ~DirectoryEnumerationOptions.Folders;
  417. options |= DirectoryEnumerationOptions.Files;
  418. return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, options, PathFormat.RelativePath);
  419. }
  420. /// <summary>[AlphaFS] Returns an enumerable collection of file 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 files in the directory specified by <paramref name="path"/> and that match the <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> EnumerateFilesTransacted(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options, PathFormat pathFormat)
  439. {
  440. // Adhere to the method name.
  441. options &= ~DirectoryEnumerationOptions.Folders;
  442. options |= DirectoryEnumerationOptions.Files;
  443. return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, options, pathFormat);
  444. }
  445. #endregion // Transactional
  446. }
  447. }