Esempio n. 1
0
        // http://stackoverflow.com/questions/8991192/check-filesize-without-opening-file-in-c
        public override long GetSize()
        {
            using (var fh = LongPathFile.GetFileHandle(Path,
                                                       FileMode.Open, FileAccess.Read, FileShare.ReadWrite, FileOptions.None))
            {
                if (fh.IsInvalid)
                {
                    throw LongPathCommon.GetExceptionFromLastWin32Error();
                }

                long size;
                if (NativeMethods.GetFileSizeEx(fh, out size))
                {
                    return(size);
                }

                throw LongPathCommon.GetExceptionFromLastWin32Error();
            }
        }
Esempio n. 2
0
        public override DateTimeOffset?GetLastModifiedTimeUtc()
        {
            if (!Exists())
            {
                return(null);
            }

            WIN32_FILE_ATTRIBUTE_DATA data;

            if (!NativeMethods.GetFileAttributesEx(
                    Path.LongFullPath,
                    GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard,
                    out data))
            {
                throw LongPathCommon.GetExceptionFromLastWin32Error();
            }

            var ft = data.ftLastWriteTime;

            return(DateTime.FromFileTime((((long)ft.dwHighDateTime) << 32) + ft.dwLowDateTime));
        }