Directory.GetDirectories(path) 返回完整路径还是仅返回名称?
在 MSDN 文档中,它说它只返回目录名称(“返回值 类型: ... 包含路径中子目录名称的 String 类型数组。”),但是在他们的示例代码中,他们递归而不连接它们,所以这是否意味着他们返回完整路径?
即他们的示例代码:
public static void ProcessDirectory(string targetDirectory)
{
// Process the list of files found in the directory.
string [] fileEntries = Directory.GetFiles(targetDirectory);
foreach(string fileName in fileEntries)
ProcessFile(fileName);
// Recurse into subdirectories of this directory.
string [] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
foreach(string subdirectory in subdirectoryEntries)
ProcessDirectory(subdirectory);
}
如果 GetDirectories 方法仅返回目录名称,则将不起作用!
In the MSDN documentation, it says it returns just directory names("Return Value
Type: ...
An array of type String containing the names of subdirectories in path."), however in their example code, they recurse without concatenating them, so does that mean they return the full paths?
i.e. their example code:
public static void ProcessDirectory(string targetDirectory) { // Process the list of files found in the directory. string [] fileEntries = Directory.GetFiles(targetDirectory); foreach(string fileName in fileEntries) ProcessFile(fileName);// Recurse into subdirectories of this directory. string [] subdirectoryEntries = Directory.GetDirectories(targetDirectory); foreach(string subdirectory in subdirectoryEntries) ProcessDirectory(subdirectory); }
would not work if the GetDirectories method only returned directory names!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如函数的 MSDN 页面中指定的那样:
As specified in the function's MSDN page:
它返回完整路径。您可以使用 PowerShell 进行验证:
It returns full paths. You can verify with PowerShell: