Pchp.Library.Streams.FileStreamWrapper.Listing C# (CSharp) Method

Listing() public method

public Listing ( string path, StreamListingOptions options, StreamContext context ) : string[]
path string
options StreamListingOptions
context StreamContext
return string[]
        public override string[] Listing(string path, StreamListingOptions options, StreamContext context)
        {
            Debug.Assert(path != null);
            Debug.Assert(Path.IsPathRooted(path));

            try
            {
                string[] listing = Directory.GetFileSystemEntries(path);
                bool root = Path.GetPathRoot(path) == path;
                int index = root ? 0 : 2;
                string[] rv = new string[listing.Length + index];

                // Remove the absolute path information (PHP returns only filenames)
                int pathLength = path.Length;
                if (path[pathLength - 1] != Path.DirectorySeparatorChar) pathLength++;

                // Check for the '.' and '..'; they should be present
                if (!root)
                {
                    rv[0] = ".";
                    rv[1] = "..";
                }
                for (int i = 0; i < listing.Length; i++)
                {
                    rv[index++] = listing[i].Substring(pathLength);
                }
                return rv;
            }
            catch (DirectoryNotFoundException)
            {
                PhpException.Throw(PhpError.Warning, ErrResources.stream_bad_directory, FileSystemUtils.StripPassword(path));
            }
            catch (UnauthorizedAccessException)
            {
                PhpException.Throw(PhpError.Warning, ErrResources.stream_file_access_denied, FileSystemUtils.StripPassword(path));
            }
            catch (System.Exception e)
            {
                PhpException.Throw(PhpError.Warning, ErrResources.stream_error, FileSystemUtils.StripPassword(path), e.Message);
            }
            return null;
        }