Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

671 wiersze
40 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 Directory
  29. {
  30. /// <summary>[AlphaFS] Returns an enumerable collection of file system entries in a specified path.</summary>
  31. /// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
  32. /// <exception cref="ArgumentException"/>
  33. /// <exception cref="ArgumentNullException"/>
  34. /// <exception cref="DirectoryNotFoundException"/>
  35. /// <exception cref="IOException"/>
  36. /// <exception cref="NotSupportedException"/>
  37. /// <exception cref="UnauthorizedAccessException"/>
  38. /// <typeparam name="T">The type to return. This may be one of the following types:
  39. /// <list type="definition">
  40. /// <item>
  41. /// <term><see cref="FileSystemEntryInfo"/></term>
  42. /// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
  43. /// </item>
  44. /// <item>
  45. /// <term><see cref="FileSystemInfo"/></term>
  46. /// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
  47. /// </item>
  48. /// <item>
  49. /// <term><see cref="string"/></term>
  50. /// <description>This method will return the full path of each item.</description>
  51. /// </item>
  52. /// </list>
  53. /// </typeparam>
  54. /// <param name="path">The directory to search.</param>
  55. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
  56. [SecurityCritical]
  57. public static IEnumerable<T> EnumerateFileSystemEntryInfos<T>(string path)
  58. {
  59. return EnumerateFileSystemEntryInfosCore<T>(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.RelativePath);
  60. }
  61. /// <summary>[AlphaFS] Returns an enumerable collection of file system entries in a specified path.</summary>
  62. /// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
  63. /// <exception cref="ArgumentException"/>
  64. /// <exception cref="ArgumentNullException"/>
  65. /// <exception cref="DirectoryNotFoundException"/>
  66. /// <exception cref="IOException"/>
  67. /// <exception cref="NotSupportedException"/>
  68. /// <exception cref="UnauthorizedAccessException"/>
  69. /// <typeparam name="T">The type to return. This may be one of the following types:
  70. /// <list type="definition">
  71. /// <item>
  72. /// <term><see cref="FileSystemEntryInfo"/></term>
  73. /// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
  74. /// </item>
  75. /// <item>
  76. /// <term><see cref="FileSystemInfo"/></term>
  77. /// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
  78. /// </item>
  79. /// <item>
  80. /// <term><see cref="string"/></term>
  81. /// <description>This method will return the full path of each item.</description>
  82. /// </item>
  83. /// </list>
  84. /// </typeparam>
  85. /// <param name="path">The directory to search.</param>
  86. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  87. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
  88. [SecurityCritical]
  89. public static IEnumerable<T> EnumerateFileSystemEntryInfos<T>(string path, PathFormat pathFormat)
  90. {
  91. return EnumerateFileSystemEntryInfosCore<T>(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, pathFormat);
  92. }
  93. /// <summary>[AlphaFS] Returns an enumerable collection of file system entries in a specified path.</summary>
  94. /// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
  95. /// <exception cref="ArgumentException"/>
  96. /// <exception cref="ArgumentNullException"/>
  97. /// <exception cref="DirectoryNotFoundException"/>
  98. /// <exception cref="IOException"/>
  99. /// <exception cref="NotSupportedException"/>
  100. /// <exception cref="UnauthorizedAccessException"/>
  101. /// <typeparam name="T">The type to return. This may be one of the following types:
  102. /// <list type="definition">
  103. /// <item>
  104. /// <term><see cref="FileSystemEntryInfo"/></term>
  105. /// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
  106. /// </item>
  107. /// <item>
  108. /// <term><see cref="FileSystemInfo"/></term>
  109. /// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
  110. /// </item>
  111. /// <item>
  112. /// <term><see cref="string"/></term>
  113. /// <description>This method will return the full path of each item.</description>
  114. /// </item>
  115. /// </list>
  116. /// </typeparam>
  117. /// <param name="path">The directory to search.</param>
  118. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  119. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
  120. [SecurityCritical]
  121. public static IEnumerable<T> EnumerateFileSystemEntryInfos<T>(string path, DirectoryEnumerationOptions options)
  122. {
  123. return EnumerateFileSystemEntryInfosCore<T>(null, path, Path.WildcardStarMatchAll, options, PathFormat.RelativePath);
  124. }
  125. /// <summary>[AlphaFS] Returns an enumerable collection of file system entries in a specified path.</summary>
  126. /// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
  127. /// <exception cref="ArgumentException"/>
  128. /// <exception cref="ArgumentNullException"/>
  129. /// <exception cref="DirectoryNotFoundException"/>
  130. /// <exception cref="IOException"/>
  131. /// <exception cref="NotSupportedException"/>
  132. /// <exception cref="UnauthorizedAccessException"/>
  133. /// <typeparam name="T">The type to return. This may be one of the following types:
  134. /// <list type="definition">
  135. /// <item>
  136. /// <term><see cref="FileSystemEntryInfo"/></term>
  137. /// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
  138. /// </item>
  139. /// <item>
  140. /// <term><see cref="FileSystemInfo"/></term>
  141. /// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
  142. /// </item>
  143. /// <item>
  144. /// <term><see cref="string"/></term>
  145. /// <description>This method will return the full path of each item.</description>
  146. /// </item>
  147. /// </list>
  148. /// </typeparam>
  149. /// <param name="path">The directory to search.</param>
  150. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  151. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  152. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
  153. [SecurityCritical]
  154. public static IEnumerable<T> EnumerateFileSystemEntryInfos<T>(string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
  155. {
  156. return EnumerateFileSystemEntryInfosCore<T>(null, path, Path.WildcardStarMatchAll, options, pathFormat);
  157. }
  158. /// <summary>[AlphaFS] Returns an enumerable collection of file system entries that match a <paramref name="searchPattern" /> in a specified path.</summary>
  159. /// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
  160. /// <exception cref="ArgumentException"/>
  161. /// <exception cref="ArgumentNullException"/>
  162. /// <exception cref="DirectoryNotFoundException"/>
  163. /// <exception cref="IOException"/>
  164. /// <exception cref="NotSupportedException"/>
  165. /// <exception cref="UnauthorizedAccessException"/>
  166. /// <typeparam name="T">The type to return. This may be one of the following types:
  167. /// <list type="definition">
  168. /// <item>
  169. /// <term><see cref="FileSystemEntryInfo"/></term>
  170. /// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
  171. /// </item>
  172. /// <item>
  173. /// <term><see cref="FileSystemInfo"/></term>
  174. /// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
  175. /// </item>
  176. /// <item>
  177. /// <term><see cref="string"/></term>
  178. /// <description>This method will return the full path of each item.</description>
  179. /// </item>
  180. /// </list>
  181. /// </typeparam>
  182. /// <param name="path">The directory to search.</param>
  183. /// <param name="searchPattern">
  184. /// The search string to match against the names of directories in <paramref name="path"/>.
  185. /// This parameter can contain a combination of valid literal path and wildcard
  186. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  187. /// </param>
  188. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
  189. [SecurityCritical]
  190. public static IEnumerable<T> EnumerateFileSystemEntryInfos<T>(string path, string searchPattern)
  191. {
  192. return EnumerateFileSystemEntryInfosCore<T>(null, path, searchPattern, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.RelativePath);
  193. }
  194. /// <summary>[AlphaFS] Returns an enumerable collection of file system entries that match a <paramref name="searchPattern"/> in a specified path.</summary>
  195. /// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
  196. /// <exception cref="ArgumentException"/>
  197. /// <exception cref="ArgumentNullException"/>
  198. /// <exception cref="DirectoryNotFoundException"/>
  199. /// <exception cref="IOException"/>
  200. /// <exception cref="NotSupportedException"/>
  201. /// <exception cref="UnauthorizedAccessException"/>
  202. /// <typeparam name="T">The type to return. This may be one of the following types:
  203. /// <list type="definition">
  204. /// <item>
  205. /// <term><see cref="FileSystemEntryInfo"/></term>
  206. /// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
  207. /// </item>
  208. /// <item>
  209. /// <term><see cref="FileSystemInfo"/></term>
  210. /// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
  211. /// </item>
  212. /// <item>
  213. /// <term><see cref="string"/></term>
  214. /// <description>This method will return the full path of each item.</description>
  215. /// </item>
  216. /// </list>
  217. /// </typeparam>
  218. /// <param name="path">The directory to search.</param>
  219. /// <param name="searchPattern">
  220. /// The search string to match against the names of directories in <paramref name="path"/>.
  221. /// This parameter can contain a combination of valid literal path and wildcard
  222. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  223. /// </param>
  224. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  225. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
  226. [SecurityCritical]
  227. public static IEnumerable<T> EnumerateFileSystemEntryInfos<T>(string path, string searchPattern, PathFormat pathFormat)
  228. {
  229. return EnumerateFileSystemEntryInfosCore<T>(null, path, searchPattern, DirectoryEnumerationOptions.FilesAndFolders, pathFormat);
  230. }
  231. /// <summary>[AlphaFS] Returns an enumerable collection of file system entries that match a <paramref name="searchPattern"/> in a specified path using <see cref="DirectoryEnumerationOptions"/>.</summary>
  232. /// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
  233. /// <exception cref="ArgumentException"/>
  234. /// <exception cref="ArgumentNullException"/>
  235. /// <exception cref="DirectoryNotFoundException"/>
  236. /// <exception cref="IOException"/>
  237. /// <exception cref="NotSupportedException"/>
  238. /// <exception cref="UnauthorizedAccessException"/>
  239. /// <typeparam name="T">The type to return. This may be one of the following types:
  240. /// <list type="definition">
  241. /// <item>
  242. /// <term><see cref="FileSystemEntryInfo"/></term>
  243. /// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
  244. /// </item>
  245. /// <item>
  246. /// <term><see cref="FileSystemInfo"/></term>
  247. /// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
  248. /// </item>
  249. /// <item>
  250. /// <term><see cref="string"/></term>
  251. /// <description>This method will return the full path of each item.</description>
  252. /// </item>
  253. /// </list>
  254. /// </typeparam>
  255. /// <param name="path">The directory to search.</param>
  256. /// <param name="searchPattern">
  257. /// The search string to match against the names of directories in <paramref name="path"/>.
  258. /// This parameter can contain a combination of valid literal path and wildcard
  259. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  260. /// </param>
  261. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  262. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
  263. [SecurityCritical]
  264. public static IEnumerable<T> EnumerateFileSystemEntryInfos<T>(string path, string searchPattern, DirectoryEnumerationOptions options)
  265. {
  266. return EnumerateFileSystemEntryInfosCore<T>(null, path, searchPattern, options, PathFormat.RelativePath);
  267. }
  268. /// <summary>[AlphaFS] Returns an enumerable collection of file system entries that match a <paramref name="searchPattern"/> in a specified path using <see cref="DirectoryEnumerationOptions"/>.</summary>
  269. /// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
  270. /// <exception cref="ArgumentException"/>
  271. /// <exception cref="ArgumentNullException"/>
  272. /// <exception cref="DirectoryNotFoundException"/>
  273. /// <exception cref="IOException"/>
  274. /// <exception cref="NotSupportedException"/>
  275. /// <exception cref="UnauthorizedAccessException"/>
  276. /// <typeparam name="T">The type to return. This may be one of the following types:
  277. /// <list type="definition">
  278. /// <item>
  279. /// <term><see cref="FileSystemEntryInfo"/></term>
  280. /// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
  281. /// </item>
  282. /// <item>
  283. /// <term><see cref="FileSystemInfo"/></term>
  284. /// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
  285. /// </item>
  286. /// <item>
  287. /// <term><see cref="string"/></term>
  288. /// <description>This method will return the full path of each item.</description>
  289. /// </item>
  290. /// </list>
  291. /// </typeparam>
  292. /// <param name="path">The directory to search.</param>
  293. /// <param name="searchPattern">
  294. /// The search string to match against the names of directories in <paramref name="path"/>.
  295. /// This parameter can contain a combination of valid literal path and wildcard
  296. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  297. /// </param>
  298. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  299. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  300. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
  301. [SecurityCritical]
  302. public static IEnumerable<T> EnumerateFileSystemEntryInfos<T>(string path, string searchPattern, DirectoryEnumerationOptions options, PathFormat pathFormat)
  303. {
  304. return EnumerateFileSystemEntryInfosCore<T>(null, path, searchPattern, options, pathFormat);
  305. }
  306. #region Transactional
  307. /// <summary>[AlphaFS] Returns an enumerable collection of file system entries in a specified path.</summary>
  308. /// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
  309. /// <exception cref="ArgumentException"/>
  310. /// <exception cref="ArgumentNullException"/>
  311. /// <exception cref="DirectoryNotFoundException"/>
  312. /// <exception cref="IOException"/>
  313. /// <exception cref="NotSupportedException"/>
  314. /// <exception cref="UnauthorizedAccessException"/>
  315. /// <typeparam name="T">The type to return. This may be one of the following types:
  316. /// <list type="definition">
  317. /// <item>
  318. /// <term><see cref="FileSystemEntryInfo"/></term>
  319. /// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
  320. /// </item>
  321. /// <item>
  322. /// <term><see cref="FileSystemInfo"/></term>
  323. /// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
  324. /// </item>
  325. /// <item>
  326. /// <term><see cref="string"/></term>
  327. /// <description>This method will return the full path of each item.</description>
  328. /// </item>
  329. /// </list>
  330. /// </typeparam>
  331. /// <param name="transaction">The transaction.</param>
  332. /// <param name="path">The directory to search.</param>
  333. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
  334. [SecurityCritical]
  335. public static IEnumerable<T> EnumerateFileSystemEntryInfosTransacted<T>(KernelTransaction transaction, string path)
  336. {
  337. return EnumerateFileSystemEntryInfosCore<T>(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.RelativePath);
  338. }
  339. /// <summary>[AlphaFS] Returns an enumerable collection of file system entries in a specified path.</summary>
  340. /// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
  341. /// <exception cref="ArgumentException"/>
  342. /// <exception cref="ArgumentNullException"/>
  343. /// <exception cref="DirectoryNotFoundException"/>
  344. /// <exception cref="IOException"/>
  345. /// <exception cref="NotSupportedException"/>
  346. /// <exception cref="UnauthorizedAccessException"/>
  347. /// <typeparam name="T">The type to return. This may be one of the following types:
  348. /// <list type="definition">
  349. /// <item>
  350. /// <term><see cref="FileSystemEntryInfo"/></term>
  351. /// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
  352. /// </item>
  353. /// <item>
  354. /// <term><see cref="FileSystemInfo"/></term>
  355. /// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
  356. /// </item>
  357. /// <item>
  358. /// <term><see cref="string"/></term>
  359. /// <description>This method will return the full path of each item.</description>
  360. /// </item>
  361. /// </list>
  362. /// </typeparam>
  363. /// <param name="transaction">The transaction.</param>
  364. /// <param name="path">The directory to search.</param>
  365. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  366. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
  367. [SecurityCritical]
  368. public static IEnumerable<T> EnumerateFileSystemEntryInfosTransacted<T>(KernelTransaction transaction, string path, PathFormat pathFormat)
  369. {
  370. return EnumerateFileSystemEntryInfosCore<T>(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, pathFormat);
  371. }
  372. /// <summary>[AlphaFS] Returns an enumerable collection of file system entries in a specified path.</summary>
  373. /// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
  374. /// <exception cref="ArgumentException"/>
  375. /// <exception cref="ArgumentNullException"/>
  376. /// <exception cref="DirectoryNotFoundException"/>
  377. /// <exception cref="IOException"/>
  378. /// <exception cref="NotSupportedException"/>
  379. /// <exception cref="UnauthorizedAccessException"/>
  380. /// <typeparam name="T">The type to return. This may be one of the following types:
  381. /// <list type="definition">
  382. /// <item>
  383. /// <term><see cref="FileSystemEntryInfo"/></term>
  384. /// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
  385. /// </item>
  386. /// <item>
  387. /// <term><see cref="FileSystemInfo"/></term>
  388. /// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
  389. /// </item>
  390. /// <item>
  391. /// <term><see cref="string"/></term>
  392. /// <description>This method will return the full path of each item.</description>
  393. /// </item>
  394. /// </list>
  395. /// </typeparam>
  396. /// <param name="transaction">The transaction.</param>
  397. /// <param name="path">The directory to search.</param>
  398. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  399. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
  400. [SecurityCritical]
  401. public static IEnumerable<T> EnumerateFileSystemEntryInfosTransacted<T>(KernelTransaction transaction, string path, DirectoryEnumerationOptions options)
  402. {
  403. return EnumerateFileSystemEntryInfosCore<T>(transaction, path, Path.WildcardStarMatchAll, options, PathFormat.RelativePath);
  404. }
  405. /// <summary>[AlphaFS] Returns an enumerable collection of file system entries in a specified path.</summary>
  406. /// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
  407. /// <exception cref="ArgumentException"/>
  408. /// <exception cref="ArgumentNullException"/>
  409. /// <exception cref="DirectoryNotFoundException"/>
  410. /// <exception cref="IOException"/>
  411. /// <exception cref="NotSupportedException"/>
  412. /// <exception cref="UnauthorizedAccessException"/>
  413. /// <typeparam name="T">The type to return. This may be one of the following types:
  414. /// <list type="definition">
  415. /// <item>
  416. /// <term><see cref="FileSystemEntryInfo"/></term>
  417. /// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
  418. /// </item>
  419. /// <item>
  420. /// <term><see cref="FileSystemInfo"/></term>
  421. /// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
  422. /// </item>
  423. /// <item>
  424. /// <term><see cref="string"/></term>
  425. /// <description>This method will return the full path of each item.</description>
  426. /// </item>
  427. /// </list>
  428. /// </typeparam>
  429. /// <param name="transaction">The transaction.</param>
  430. /// <param name="path">The directory to search.</param>
  431. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  432. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  433. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
  434. [SecurityCritical]
  435. public static IEnumerable<T> EnumerateFileSystemEntryInfosTransacted<T>(KernelTransaction transaction, string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
  436. {
  437. return EnumerateFileSystemEntryInfosCore<T>(transaction, path, Path.WildcardStarMatchAll, options, pathFormat);
  438. }
  439. /// <summary>[AlphaFS] Returns an enumerable collection of file system entries that match a <paramref name="searchPattern"/> in a specified path.</summary>
  440. /// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
  441. /// <exception cref="ArgumentException"/>
  442. /// <exception cref="ArgumentNullException"/>
  443. /// <exception cref="DirectoryNotFoundException"/>
  444. /// <exception cref="IOException"/>
  445. /// <exception cref="NotSupportedException"/>
  446. /// <exception cref="UnauthorizedAccessException"/>
  447. /// <typeparam name="T">The type to return. This may be one of the following types:
  448. /// <list type="definition">
  449. /// <item>
  450. /// <term><see cref="FileSystemEntryInfo"/></term>
  451. /// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
  452. /// </item>
  453. /// <item>
  454. /// <term><see cref="FileSystemInfo"/></term>
  455. /// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
  456. /// </item>
  457. /// <item>
  458. /// <term><see cref="string"/></term>
  459. /// <description>This method will return the full path of each item.</description>
  460. /// </item>
  461. /// </list>
  462. /// </typeparam>
  463. /// <param name="transaction">The transaction.</param>
  464. /// <param name="path">The directory to search.</param>
  465. /// <param name="searchPattern">
  466. /// The search string to match against the names of directories in <paramref name="path"/>.
  467. /// This parameter can contain a combination of valid literal path and wildcard
  468. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  469. /// </param>
  470. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
  471. [SecurityCritical]
  472. public static IEnumerable<T> EnumerateFileSystemEntryInfosTransacted<T>(KernelTransaction transaction, string path, string searchPattern)
  473. {
  474. return EnumerateFileSystemEntryInfosCore<T>(transaction, path, searchPattern, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.RelativePath);
  475. }
  476. /// <summary>[AlphaFS] Returns an enumerable collection of file system entries that match a <paramref name="searchPattern"/> in a specified path.</summary>
  477. /// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
  478. /// <exception cref="ArgumentException"/>
  479. /// <exception cref="ArgumentNullException"/>
  480. /// <exception cref="DirectoryNotFoundException"/>
  481. /// <exception cref="IOException"/>
  482. /// <exception cref="NotSupportedException"/>
  483. /// <exception cref="UnauthorizedAccessException"/>
  484. /// <typeparam name="T">The type to return. This may be one of the following types:
  485. /// <list type="definition">
  486. /// <item>
  487. /// <term><see cref="FileSystemEntryInfo"/></term>
  488. /// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
  489. /// </item>
  490. /// <item>
  491. /// <term><see cref="FileSystemInfo"/></term>
  492. /// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
  493. /// </item>
  494. /// <item>
  495. /// <term><see cref="string"/></term>
  496. /// <description>This method will return the full path of each item.</description>
  497. /// </item>
  498. /// </list>
  499. /// </typeparam>
  500. /// <param name="transaction">The transaction.</param>
  501. /// <param name="path">The directory to search.</param>
  502. /// <param name="searchPattern">
  503. /// The search string to match against the names of directories in <paramref name="path"/>.
  504. /// This parameter can contain a combination of valid literal path and wildcard
  505. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  506. /// </param>
  507. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  508. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
  509. [SecurityCritical]
  510. public static IEnumerable<T> EnumerateFileSystemEntryInfosTransacted<T>(KernelTransaction transaction, string path, string searchPattern, PathFormat pathFormat)
  511. {
  512. return EnumerateFileSystemEntryInfosCore<T>(transaction, path, searchPattern, DirectoryEnumerationOptions.FilesAndFolders, pathFormat);
  513. }
  514. /// <summary>[AlphaFS] Returns an enumerable collection of file system entries that match a <paramref name="searchPattern"/> in a specified path using <see cref="DirectoryEnumerationOptions"/>.</summary>
  515. /// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
  516. /// <exception cref="ArgumentException"/>
  517. /// <exception cref="ArgumentNullException"/>
  518. /// <exception cref="DirectoryNotFoundException"/>
  519. /// <exception cref="IOException"/>
  520. /// <exception cref="NotSupportedException"/>
  521. /// <exception cref="UnauthorizedAccessException"/>
  522. /// <typeparam name="T">The type to return. This may be one of the following types:
  523. /// <list type="definition">
  524. /// <item>
  525. /// <term><see cref="FileSystemEntryInfo"/></term>
  526. /// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
  527. /// </item>
  528. /// <item>
  529. /// <term><see cref="FileSystemInfo"/></term>
  530. /// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
  531. /// </item>
  532. /// <item>
  533. /// <term><see cref="string"/></term>
  534. /// <description>This method will return the full path of each item.</description>
  535. /// </item>
  536. /// </list>
  537. /// </typeparam>
  538. /// <param name="transaction">The transaction.</param>
  539. /// <param name="path">The directory to search.</param>
  540. /// <param name="searchPattern">
  541. /// The search string to match against the names of directories in <paramref name="path"/>.
  542. /// This parameter can contain a combination of valid literal path and wildcard
  543. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  544. /// </param>
  545. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  546. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
  547. [SecurityCritical]
  548. public static IEnumerable<T> EnumerateFileSystemEntryInfosTransacted<T>(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options)
  549. {
  550. return EnumerateFileSystemEntryInfosCore<T>(transaction, path, searchPattern, options, PathFormat.RelativePath);
  551. }
  552. /// <summary>[AlphaFS] Returns an enumerable collection of file system entries that match a <paramref name="searchPattern"/> in a specified path using <see cref="DirectoryEnumerationOptions"/>.</summary>
  553. /// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
  554. /// <exception cref="ArgumentException"/>
  555. /// <exception cref="ArgumentNullException"/>
  556. /// <exception cref="DirectoryNotFoundException"/>
  557. /// <exception cref="IOException"/>
  558. /// <exception cref="NotSupportedException"/>
  559. /// <exception cref="UnauthorizedAccessException"/>
  560. /// <typeparam name="T">The type to return. This may be one of the following types:
  561. /// <list type="definition">
  562. /// <item>
  563. /// <term><see cref="FileSystemEntryInfo"/></term>
  564. /// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
  565. /// </item>
  566. /// <item>
  567. /// <term><see cref="FileSystemInfo"/></term>
  568. /// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
  569. /// </item>
  570. /// <item>
  571. /// <term><see cref="string"/></term>
  572. /// <description>This method will return the full path of each item.</description>
  573. /// </item>
  574. /// </list>
  575. /// </typeparam>
  576. /// <param name="transaction">The transaction.</param>
  577. /// <param name="path">The directory to search.</param>
  578. /// <param name="searchPattern">
  579. /// The search string to match against the names of directories in <paramref name="path"/>.
  580. /// This parameter can contain a combination of valid literal path and wildcard
  581. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  582. /// </param>
  583. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  584. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  585. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
  586. [SecurityCritical]
  587. public static IEnumerable<T> EnumerateFileSystemEntryInfosTransacted<T>(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options, PathFormat pathFormat)
  588. {
  589. return EnumerateFileSystemEntryInfosCore<T>(transaction, path, searchPattern, options, pathFormat);
  590. }
  591. #endregion // Transactional
  592. #region Internal Methods
  593. /// <summary>Returns an enumerable collection of file system entries in a specified path using <see cref="DirectoryEnumerationOptions"/>.</summary>
  594. /// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
  595. /// <exception cref="ArgumentException"/>
  596. /// <exception cref="ArgumentNullException"/>
  597. /// <exception cref="DirectoryNotFoundException"/>
  598. /// <exception cref="IOException"/>
  599. /// <exception cref="NotSupportedException"/>
  600. /// <exception cref="UnauthorizedAccessException"/>
  601. /// <typeparam name="T">The type to return. This may be one of the following types:
  602. /// <list type="definition">
  603. /// <item>
  604. /// <term><see cref="FileSystemEntryInfo"/></term>
  605. /// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
  606. /// </item>
  607. /// <item>
  608. /// <term><see cref="FileSystemInfo"/></term>
  609. /// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
  610. /// </item>
  611. /// <item>
  612. /// <term><see cref="string"/></term>
  613. /// <description>This method will return the full path of each item.</description>
  614. /// </item>
  615. /// </list>
  616. /// </typeparam>
  617. /// <param name="transaction">The transaction.</param>
  618. /// <param name="path">The directory to search.</param>
  619. /// <param name="searchPattern">
  620. /// The search string to match against the names of directories in <paramref name="path"/>.
  621. /// This parameter can contain a combination of valid literal path and wildcard
  622. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  623. /// </param>
  624. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  625. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  626. [SecurityCritical]
  627. internal static IEnumerable<T> EnumerateFileSystemEntryInfosCore<T>(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options, PathFormat pathFormat)
  628. {
  629. // Enable BasicSearch and LargeCache by default.
  630. options |= DirectoryEnumerationOptions.BasicSearch | DirectoryEnumerationOptions.LargeCache;
  631. return new FindFileSystemEntryInfo(true, transaction, path, searchPattern, options, typeof(T), pathFormat).Enumerate<T>();
  632. }
  633. #endregion // Internal Methods
  634. }
  635. }