Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

71 rader
3.5 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.IO;
  23. using System.Linq;
  24. using System.Security;
  25. namespace Alphaleonis.Win32.Filesystem
  26. {
  27. partial class DirectoryInfo
  28. {
  29. #region AlphaFS
  30. /// <summary>[AlphaFS] Counts file system objects: files, folders or both) in a given directory.</summary>
  31. /// <returns>The counted number of file system objects.</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. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  39. [SecurityCritical]
  40. public long CountFileSystemObjects(DirectoryEnumerationOptions options)
  41. {
  42. return Directory.EnumerateFileSystemEntryInfosCore<string>(Transaction, LongFullName, Path.WildcardStarMatchAll, options, PathFormat.LongFullPath).Count();
  43. }
  44. /// <summary>[AlphaFS] Counts file system objects: files, folders or both) in a given directory.</summary>
  45. /// <returns>The counted number of file system objects.</returns>
  46. /// <exception cref="ArgumentException"/>
  47. /// <exception cref="ArgumentNullException"/>
  48. /// <exception cref="DirectoryNotFoundException"/>
  49. /// <exception cref="IOException"/>
  50. /// <exception cref="NotSupportedException"/>
  51. /// <exception cref="UnauthorizedAccessException"/>
  52. /// <param name="searchPattern">
  53. /// The search string to match against the names of directories in path.
  54. /// This parameter can contain a combination of valid literal path and wildcard
  55. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  56. /// </param>
  57. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  58. [SecurityCritical]
  59. public long CountFileSystemObjects(string searchPattern, DirectoryEnumerationOptions options)
  60. {
  61. return Directory.EnumerateFileSystemEntryInfosCore<string>(Transaction, LongFullName, searchPattern, options, PathFormat.LongFullPath).Count();
  62. }
  63. #endregion // AlphaFS
  64. }
  65. }