Esempio n. 1
0
        public static DateTime GetLastWriteTime(string path)
        {
            long cTime = 0;
            long aTime = 0;
            long wTime = 0;

            using (var handle = GetFileHandleWithWrite(path))
            {
                Win32FileSystem.GetFileTime(handle, ref cTime, ref aTime, ref wTime);

                return(DateTime.FromFileTimeUtc(wTime));
            }
        }
Esempio n. 2
0
        public static void SetCreationTime(string path, DateTime creationTime)
        {
            long cTime = 0;
            long aTime = 0;
            long wTime = 0;

            using (var handle = GetFileHandleWithWrite(path))
            {
                Win32FileSystem.GetFileTime(handle, ref cTime, ref aTime, ref wTime);
                var fileTime = creationTime.ToFileTimeUtc();
                if (!Win32FileSystem.SetFileTime(handle, ref fileTime, ref aTime, ref wTime))
                {
                    ThrowWin32Exception();
                }
            }
        }