System.IO.Directory.GetFileSystemEntries C# (CSharp) Method

GetFileSystemEntries() public static method

public static GetFileSystemEntries ( string path ) : string[]
path string
return string[]
        public static string[] GetFileSystemEntries(string path) { throw null; }
        public static string[] GetFileSystemEntries(string path, string searchPattern) { throw null; }

Same methods

Directory::GetFileSystemEntries ( string path, string searchPattern ) : string[]
Directory::GetFileSystemEntries ( string path, string searchPattern, System searchOption ) : string[]

Usage Example

Esempio n. 1
0
        /// <summary>
        /// Gets a list of the contents of a directory at the specified path.
        /// </summary>
        /// <param name="path">The path of the directory to get a list of the contents of.</param>
        /// <param name="getSubDirs">Whether to obtain a list of the contents of all subdirectories as well.</param>
        /// <returns>An array of strings with the names of directories and files under the supplied path.
        /// Null if the path is invalid, does not exist, or the current process does not have permission
        /// to get the directory listing.</returns>
        static public string[] GetListing(string path, bool getSubDirs)
        {
            // Check whether the path supplied is valid.
            if (!string.IsNullOrEmpty(path))
            {
                // Check whether the path for the directory exits.
                if (SystemDirectory.Exists(path))
                {
                    // The directory exists.

                    // Check if we need to get subdirectory content as well.
                    if (!getSubDirs)
                    {
                        // We don't need to get subdirectory content.
                        try
                        {
                            return(SystemDirectory.GetFileSystemEntries(path));
                        }
                        catch (UnauthorizedAccessException)
                        {
                            // We don't have the required permission.
                            return(null);
                        }
                    }
                    else
                    {
                        // We need to get subdirectory content as well.
                        return(SystemDirectory.GetFileSystemEntries(path, "*", SearchOption.AllDirectories));
                    }
                }
            }
            // The path is not valid.
            return(null);
        }
All Usage Examples Of System.IO.Directory::GetFileSystemEntries