Get all the files and directories in the specified path

public static List<string> GetAllFiles(string dir)
        {
            return Directory.GetFiles(dir, "*", SearchOption.AllDirectories).ToList();

        }


//
        // Summary:
        //     Returns the names of files (including their paths) that match the specified search
        //     pattern in the specified directory, using a value to determine whether to search
        //     subdirectories.
        //
        // Parameters:
        //   path:
        //     The relative or absolute path to the directory to search. This string is not
        //     case-sensitive.
        //
        //   searchPattern:
        //     The search string to match against the names of files in path. This parameter
        //     can contain a combination of valid literal path and wildcard (* and ?) characters
        //     (see Remarks), but doesn't support regular expressions.
        //
        //   searchOption:
        //     One of the enumeration values that specifies whether the search operation should
        //     include all subdirectories or only the current directory.
        //
        // Returns:
        //     An array of the full names (including paths) for the files in the specified directory
        //     that match the specified search pattern and option, or an empty array if no files
        //     are found.
        //
        // Exceptions:
        //   T:System.ArgumentException:
        //     path is a zero-length string, contains only white space, or contains one or more
        //     invalid characters. You can query for invalid characters with the System.IO.Path.GetInvalidPathChars
        //     method. -or- searchPattern does not contain a valid pattern.
        //
        //   T:System.ArgumentNullException:
        //     path or searchpattern is null.
        //
        //   T:System.ArgumentOutOfRangeException:
        //     searchOption is not a valid System.IO.SearchOption value.
        //
        //   T:System.UnauthorizedAccessException:
        //     The caller does not have the required permission.
        //
        //   T:System.IO.DirectoryNotFoundException:
        //     The specified path is not found or is invalid (for example, it is on an unmapped
        //     drive).
        //
        //   T:System.IO.PathTooLongException:
        //     The specified path, file name, or both exceed the system-defined maximum length.
        //     For example, on Windows-based platforms, paths must be less than 248 characters
        //     and file names must be less than 260 characters.
        //
        //   T:System.IO.IOException:
        //     path is a file name.-or-A network error has occurred.
        public static string[] GetFiles(string path, string searchPattern, SearchOption searchOption);

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值