找不到目录名称

用户名

我想从路径获取目录名称,但是它返回以下错误:

目录名称无效

以下是示例路径:

strFilePathName = C:\ inetpub \ wwwroot \ PSSWeb \ foldername \ xxx.ini

以下Directoryname基于前缀PSS用来获取代码,其应返回PSSWeb。我无法找到解决方案。

var directories = Directory.GetDirectories(strFilePathName,
                                           "PSS?",
                                           SearchOption.AllDirectories);
Pratap Bhaskar

您指定的路径名​​“ C:\ inetpub \ wwwroot \ PSSWeb \ foldername \ xxx.ini”不是目录,而是文件。

    //
    // Summary:
    //     Returns the names of the subdirectories (including their paths) that match the
    //     specified search pattern in the specified directory, and optionally searches
    //     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 subdirectories in path. This
    //     parameter can contain a combination of valid literal and wildcard 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) of the subdirectories that match
    //     the specified criteria, or an empty array if no directories 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 by using 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.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.
    //
    //   T:System.IO.DirectoryNotFoundException:
    //     The specified path is invalid (for example, it is on an unmapped drive).
    public static string[] GetDirectories(string path, string searchPattern, SearchOption searchOption);

多数民众赞成在该方法的文档。提到第一个参数必须是目录。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

获取目录名称

来自分类Dev

父目录名称与新目录名称结合

来自分类Dev

在目录名称前添加目录名称

来自分类Dev

如何获得目录名称

来自分类Dev

在目录名称中使用“&”

来自分类Dev

排除目录名称-ruby

来自分类Dev

模块名称和目录名称冲突?

来自分类Dev

在模板目录中找不到模板名称“ play-java”

来自分类Dev

资产目录错误:CUICatalog:找不到名称的表达形式

来自分类Dev

找不到与参数名称“目录”匹配的参数

来自分类Dev

为什么此脚本找不到名称以空格结尾的目录

来自分类Dev

通过.htaccess从URL隐藏目录名称

来自分类Dev

检查PWD是否包含目录名称

来自分类Dev

TFSBuild / Release Manager:目录名称无效

来自分类Dev

从URL删除目录名称Wordpress

来自分类Dev

指定VS扩展安装目录名称

来自分类Dev

在bash中增加目录名称

来自分类Dev

htaccess重写并传递顶级目录名称

来自分类Dev

使用Powershell对目录名称进行排序

来自分类Dev

从批次中的数组获取目录名称

来自分类Dev

通过PowerShell获取Azure目录名称

来自分类Dev

solr复制目录名称未使用

来自分类Dev

只需输入目录名称即可cd?

来自分类Dev

列出符号链接的目录名称

来自分类Dev

从URL中删除目录名称Wordpress

来自分类Dev

从URL删除MVC目录名称

来自分类Dev

使用PHP获取当前目录名称?

来自分类Dev

Rewriterule别名与目录名称匹配吗?

来自分类Dev

在bash中增加目录名称