/// <summary>
        /// Enumerate the files of this directory.
        /// </summary>
        /// <param name="searchPattern">The search string. The default pattern is "*", which returns all files.</param>
        /// <param name="searchOption">One of the enumeration values that specifies whether the search operation should include only the current directory or all subdirectories. The default value is TopDirectoryOnly.</param>
        /// <exception cref="T:System.Net.WebException"></exception>
        /// <exception cref="T:Amazon.S3.AmazonS3Exception"></exception>
        /// <returns>An enumerable collection of files that matches searchPattern and searchOption.</returns>
        public IEnumerable <S3FileInfo> EnumerateFiles(string searchPattern, SearchOption searchOption)
        {
            IEnumerable <S3FileInfo> files = null;

            if (String.IsNullOrEmpty(bucket))
            {
                files = new List <S3FileInfo>();
            }
            else
            {
                var request = new ListObjectsRequest
                {
                    BucketName = bucket,
                    Delimiter  = "/",
                    Prefix     = S3Helper.EncodeKey(key)
                };
                ((Amazon.Runtime.Internal.IAmazonWebServiceRequest)request).AddBeforeRequestHandler(S3Helper.FileIORequestEventHandler);
                PaginatedResourceInfo pagingInfo = new PaginatedResourceInfo().WithClient(s3Client)
                                                   .WithMethodName("ListObjects")
                                                   .WithRequest(request)
                                                   .WithItemListPropertyPath("S3Objects")
                                                   .WithTokenRequestPropertyPath("Marker")
                                                   .WithTokenResponsePropertyPath("NextMarker");

                files = new EnumerableConverter <S3Object, S3FileInfo>
                            (((IEnumerable <S3Object>)(PaginatedResourceFactory.Create <S3Object, ListObjectsRequest, ListObjectsResponse>(pagingInfo)))
                            .Where(s3Object => !String.Equals(S3Helper.DecodeKey(s3Object.Key), key, StringComparison.Ordinal) && !s3Object.Key.EndsWith("\\", StringComparison.Ordinal)),
                            s3Object => new S3FileInfo(s3Client, bucket, S3Helper.DecodeKey(s3Object.Key)));
            }

            //handle if recursion is set
            if (searchOption == SearchOption.AllDirectories)
            {
                IEnumerable <S3DirectoryInfo> foldersToSearch = EnumerateDirectories();
                foreach (S3DirectoryInfo dir in foldersToSearch)
                {
                    files = files.Concat(dir.EnumerateFiles(searchPattern, searchOption));
                }
            }

            //filter based on search pattern
            var regEx = WildcardToRegex(searchPattern);

            files = files.Where(s3fileInfo => Regex.IsMatch(s3fileInfo.Name, regEx, RegexOptions.IgnoreCase));
            return(files);
        }
 internal ConvertingEnumerator(EnumerableConverter <T, U> ec)
 {
     getT    = ec.baseEnum.GetEnumerator();
     convert = ec.converter;
 }