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.

Directory.GetLastAccessTime.cs 7.0 KiB

7 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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.Security;
  23. namespace Alphaleonis.Win32.Filesystem
  24. {
  25. partial class Directory
  26. {
  27. #region .NET
  28. /// <summary>Gets the date and time that the specified directory was last accessed.</summary>
  29. /// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified directory was last accessed. This value is expressed in local time.</returns>
  30. /// <param name="path">The directory for which to obtain access date and time information.</param>
  31. [SecurityCritical]
  32. public static DateTime GetLastAccessTime(string path)
  33. {
  34. return File.GetLastAccessTimeCore(null, path, false, PathFormat.RelativePath).ToLocalTime();
  35. }
  36. /// <summary>Gets the date and time, in coordinated universal time (UTC), that the specified directory was last accessed.</summary>
  37. /// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified directory was last accessed. This value is expressed in UTC time.</returns>
  38. /// <param name="path">The directory for which to obtain access date and time information.</param>
  39. [SecurityCritical]
  40. public static DateTime GetLastAccessTimeUtc(string path)
  41. {
  42. return File.GetLastAccessTimeCore(null, path, true, PathFormat.RelativePath);
  43. }
  44. #endregion // .NET
  45. /// <summary>[AlphaFS] Gets the date and time that the specified directory was last accessed.</summary>
  46. /// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified directory was last accessed. This value is expressed in local time.</returns>
  47. /// <param name="path">The directory for which to obtain access date and time information.</param>
  48. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  49. [SecurityCritical]
  50. public static DateTime GetLastAccessTime(string path, PathFormat pathFormat)
  51. {
  52. return File.GetLastAccessTimeCore(null, path, false, pathFormat).ToLocalTime();
  53. }
  54. /// <summary>[AlphaFS] Gets the date and time, in coordinated universal time (UTC), that the specified directory was last accessed.</summary>
  55. /// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified directory was last accessed. This value is expressed in UTC time.</returns>
  56. /// <param name="path">The directory for which to obtain access date and time information.</param>
  57. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  58. [SecurityCritical]
  59. public static DateTime GetLastAccessTimeUtc(string path, PathFormat pathFormat)
  60. {
  61. return File.GetLastAccessTimeCore(null, path, true, pathFormat);
  62. }
  63. #region Transactional
  64. /// <summary>[AlphaFS] Gets the date and time that the specified directory was last accessed.</summary>
  65. /// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified directory was last accessed. This value is expressed in local time.</returns>
  66. /// <param name="transaction">The transaction.</param>
  67. /// <param name="path">The directory for which to obtain access date and time information.</param>
  68. [SecurityCritical]
  69. public static DateTime GetLastAccessTimeTransacted(KernelTransaction transaction, string path)
  70. {
  71. return File.GetLastAccessTimeCore(transaction, path, false, PathFormat.RelativePath).ToLocalTime();
  72. }
  73. /// <summary>[AlphaFS] Gets the date and time that the specified directory was last accessed.</summary>
  74. /// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified directory was last accessed. This value is expressed in local time.</returns>
  75. /// <param name="transaction">The transaction.</param>
  76. /// <param name="path">The directory for which to obtain access date and time information.</param>
  77. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  78. [SecurityCritical]
  79. public static DateTime GetLastAccessTimeTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
  80. {
  81. return File.GetLastAccessTimeCore(transaction, path, false, pathFormat).ToLocalTime();
  82. }
  83. /// <summary>[AlphaFS] Gets the date and time, in coordinated universal time (UTC), that the specified directory was last accessed.</summary>
  84. /// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified directory was last accessed. This value is expressed in UTC time.</returns>
  85. /// <param name="transaction">The transaction.</param>
  86. /// <param name="path">The directory for which to obtain access date and time information.</param>
  87. [SecurityCritical]
  88. public static DateTime GetLastAccessTimeUtcTransacted(KernelTransaction transaction, string path)
  89. {
  90. return File.GetLastAccessTimeCore(transaction, path, true, PathFormat.RelativePath);
  91. }
  92. /// <summary>[AlphaFS] Gets the date and time, in coordinated universal time (UTC), that the specified directory was last accessed.</summary>
  93. /// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified directory was last accessed. This value is expressed in UTC time.</returns>
  94. /// <param name="transaction">The transaction.</param>
  95. /// <param name="path">The directory for which to obtain access date and time information.</param>
  96. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  97. [SecurityCritical]
  98. public static DateTime GetLastAccessTimeUtcTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
  99. {
  100. return File.GetLastAccessTimeCore(transaction, path, true, pathFormat);
  101. }
  102. #endregion // Transactional
  103. }
  104. }