コード例 #1
0
        public static unsafe void SetLastAccessTimeUtc(string path, DateTime lastWriteTimeUtc)
        {
            var normalizedPath = Path.NormalizeLongPath(Path.GetFullPath(path));

            using (var handle = GetDirectoryHandle(normalizedPath))
            {
                var fileTime = new NativeMethods.FILE_TIME(lastWriteTimeUtc.ToFileTimeUtc());
                var r        = NativeMethods.SetFileTime(handle, null, &fileTime, null);
                if (r)
                {
                    return;
                }
                var errorCode = Marshal.GetLastWin32Error();
                Common.ThrowIOError(errorCode, path);
            }
        }
コード例 #2
0
ファイル: File.cs プロジェクト: practicegithub2016/LongPath
        public static unsafe void SetLastAccessTimeUtc(String path, DateTime lastAccessTimeUtc)
        {
            string normalizedPath = Path.NormalizeLongPath(path);

            using (SafeFileHandle handle = GetFileHandle(normalizedPath,
                                                         FileMode.Open, FileAccess.Write, FileShare.ReadWrite, FileOptions.None))
            {
                var  fileTime = new NativeMethods.FILE_TIME(lastAccessTimeUtc.ToFileTimeUtc());
                bool r        = NativeMethods.SetFileTime(handle, null, &fileTime, null);
                if (!r)
                {
                    int errorCode = Marshal.GetLastWin32Error();
                    Common.ThrowIOError(errorCode, path);
                }
            }
        }
コード例 #3
0
ファイル: File.cs プロジェクト: bangush/LongPath
        public static unsafe void SetCreationTimeUtc(String path, DateTime creationTimeUtc)
        {
            if (Common.IsRunningOnMono() && Common.IsPlatformUnix())
            {
                SysFile.SetCreationTimeUtc(path, creationTimeUtc);
                return;
            }

            string normalizedPath = Path.NormalizeLongPath(path);

            using (SafeFileHandle handle = GetFileHandle(normalizedPath,
                                                         FileMode.Open, FileAccess.Write, FileShare.ReadWrite, FileOptions.None))
            {
                var  fileTime = new NativeMethods.FILE_TIME(creationTimeUtc.ToFileTimeUtc());
                bool r        = NativeMethods.SetFileTime(handle, &fileTime, null, null);
                if (!r)
                {
                    int errorCode = Marshal.GetLastWin32Error();
                    Common.ThrowIOError(errorCode, path);
                }
            }
        }
コード例 #4
0
ファイル: Directory.cs プロジェクト: jerriclynsjohn/LongPath
        public static unsafe void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc)
        {
            var normalizedPath = Path.NormalizeLongPath(Path.GetFullPath(path));

            using (SafeFileHandle handle = GetDirectoryHandle(normalizedPath))
            {
                var fileTime = new NativeMethods.FILE_TIME(lastWriteTimeUtc.ToFileTimeUtc());
                bool r = NativeMethods.SetFileTime(handle, null, null, &fileTime);
                if (!r)
                {
                    int errorCode = Marshal.GetLastWin32Error();
                    Common.ThrowIOError(errorCode, path);
                }
            }
        }
コード例 #5
0
ファイル: File.cs プロジェクト: KsWare/LongPath
 public static unsafe void SetLastWriteTimeUtc(String path, DateTime lastWriteTimeUtc)
 {
     string normalizedPath = Path.NormalizeLongPath(path);
     using (SafeFileHandle handle = GetFileHandle(normalizedPath,
         FileMode.Open, FileAccess.Write, FileShare.ReadWrite, FileOptions.None))
     {
         var fileTime = new NativeMethods.FILE_TIME(lastWriteTimeUtc.ToFileTimeUtc());
         bool r = NativeMethods.SetFileTime(handle, null, null, &fileTime);
         if (!r)
         {
             int errorCode = Marshal.GetLastWin32Error();
             Common.ThrowIOError(errorCode, path);
         }
     }
 }
コード例 #6
0
ファイル: Directory.cs プロジェクト: red-gate/LongPath
        public static unsafe void SetCreationTimeUtc(string path, DateTime creationTimeUtc)
        {
            var normalizedPath = Path.NormalizeLongPath(Path.GetFullPath(path));

            using (var handle = GetDirectoryHandle(normalizedPath))
            {
                var fileTime = new NativeMethods.FILE_TIME(creationTimeUtc.ToFileTimeUtc());
                var r = NativeMethods.SetFileTime(handle, &fileTime, null, null);
                if (r) return;
                var errorCode = Marshal.GetLastWin32Error();
                Common.ThrowIOError(errorCode, path);
            }
        }