예제 #1
0
        public FileInfo(string path)
        {
            FullName = path;
            Name     = Path.GetFileName(path);

            if (unix.IsUnix)
            {
                System.IO.FileInfo fi = new System.IO.FileInfo(path);

                if (!fi.Exists)
                {
                    return;
                }

                Length        = fi.Length;
                LastWriteTime = fi.LastWriteTimeUtc.Ticks;
                return;
            }

            string fileName = NameFix.AddLongPathPrefix(path);

            Win32Native.WIN32_FILE_ATTRIBUTE_DATA wIn32FileAttributeData = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA();

            bool b = Win32Native.GetFileAttributesEx(fileName, 0, ref wIn32FileAttributeData);

            if (!b || (wIn32FileAttributeData.fileAttributes & Win32Native.FILE_ATTRIBUTE_DIRECTORY) != 0)
            {
                return;
            }

            Length        = FileParamConvert.Length(wIn32FileAttributeData.fileSizeHigh, wIn32FileAttributeData.fileSizeLow);
            LastWriteTime = FileParamConvert.Time(wIn32FileAttributeData.ftLastWriteTimeHigh, wIn32FileAttributeData.ftLastWriteTimeLow);
        }
예제 #2
0
        public FileInfo[] GetFiles(string SearchPattern, bool includeHidden = true)
        {
            List <FileInfo> files = new List <FileInfo>();

            if (unix.IsUnix)
            {
                System.IO.DirectoryInfo di    = new System.IO.DirectoryInfo(FullName);
                System.IO.FileInfo[]    arrDi = di.GetFiles(SearchPattern);
                foreach (System.IO.FileInfo tDi in arrDi)
                {
                    FileInfo lDi = new FileInfo
                    {
                        Name          = tDi.Name,
                        FullName      = Path.Combine(FullName, tDi.Name),
                        Length        = tDi.Length,
                        LastWriteTime = tDi.LastWriteTimeUtc.Ticks
                    };
                    files.Add(lDi);
                }
                return(files.ToArray());
            }

            string dirName = NameFix.AddLongPathPrefix(FullName);

            Win32Native.WIN32_FIND_DATA findData = new Win32Native.WIN32_FIND_DATA();
            SafeFindHandle findHandle            = Win32Native.FindFirstFile(dirName + @"\" + SearchPattern, findData);

            if (!findHandle.IsInvalid)
            {
                do
                {
                    string currentFileName = findData.cFileName;

                    // if this is a directory, find its contents
                    if ((findData.dwFileAttributes & Win32Native.FILE_ATTRIBUTE_DIRECTORY) != 0)
                    {
                        continue;
                    }
                    if (!includeHidden && (findData.dwFileAttributes & Win32Native.FILE_ATTRIBUTE_HIDDEN) != 0)
                    {
                        continue;
                    }

                    FileInfo fi = new FileInfo
                    {
                        Name          = currentFileName,
                        FullName      = Path.Combine(FullName, currentFileName),
                        Length        = FileParamConvert.Length(findData.nFileSizeHigh, findData.nFileSizeLow),
                        LastWriteTime = FileParamConvert.Time(findData.ftLastWriteTimeHigh, findData.ftLastWriteTimeLow)
                    };
                    files.Add(fi);
                }while (Win32Native.FindNextFile(findHandle, findData));
            }

            // close the find handle
            findHandle.Dispose();

            return(files.ToArray());
        }