Exemplo n.º 1
0
        public FileInfo[] GetFiles(string SearchPattern, bool includeHidden = true)
        {
            List <FileInfo> files = new List <FileInfo>();

            if (Settings.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        = Convert.Length(findData.nFileSizeHigh, findData.nFileSizeLow),
                        LastWriteTime = Convert.Time(findData.ftLastWriteTimeHigh, findData.ftLastWriteTimeLow)
                    };
                    files.Add(fi);
                }while (Win32Native.FindNextFile(findHandle, findData));
            }

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

            return(files.ToArray());
        }
Exemplo n.º 2
0
        public DirectoryInfo[] GetDirectories(string SearchPattern, bool includeHidden = true)
        {
            List <DirectoryInfo> dirs = new List <DirectoryInfo>();

            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 (currentFileName == "." || currentFileName == "..")
                    {
                        continue;
                    }
                    if (!includeHidden && (findData.dwFileAttributes & Win32Native.FILE_ATTRIBUTE_HIDDEN) != 0)
                    {
                        continue;
                    }

                    DirectoryInfo di = new DirectoryInfo
                    {
                        Name           = currentFileName,
                        FullName       = Path.Combine(FullName, currentFileName),
                        LastWriteTime  = Convert.Time(findData.ftLastWriteTimeHigh, findData.ftLastWriteTimeLow),
                        fileAttributes = findData.dwFileAttributes
                    };
                    dirs.Add(di);
                }while (Win32Native.FindNextFile(findHandle, findData));
            }

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

            return(dirs.ToArray());
        }
Exemplo n.º 3
0
        public FileInfo[] GetFiles(string SearchPattern, bool includeHidden = true)
        {
            List<FileInfo> files = new List<FileInfo>();

            if (Settings.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 = Convert.Length(findData.nFileSizeHigh, findData.nFileSizeLow),
                        LastWriteTime = Convert.Time(findData.ftLastWriteTimeHigh, findData.ftLastWriteTimeLow)
                    };
                    files.Add(fi);
                }
                while (Win32Native.FindNextFile(findHandle, findData));
            }

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

            return files.ToArray();
        }