如何从文件位置遍历一个文件夹? [英] How Do I Traverse One Folder Up From File Location?

查看:71
本文介绍了如何从文件位置遍历一个文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从存储过程中提取的路径。路径指向一个文件,但我想遍历一个文件夹。我该如何处理这个问题?

提取路径的代码是:

extractedPath = Convert.ToString(cmd2.ExecuteScalar())

解决方案

< blockquote>

 使用 System.IO; 
// ...
string x = Path.GetDirectoryName(extractedPath); // 包含文件夹
string y = Path.GetDirectoryName(x); // 1个文件夹



y be be be null,如果x是根文件夹(例如x = C:\)


I have a path extracted from stored procedure.The path points to a file but i want to traverse one folder up. How should i approach to the problem?
The code for path extracted is:
extractedPath =Convert.ToString( cmd2.ExecuteScalar())

解决方案

using System.IO;
// ...
string x = Path.GetDirectoryName(extractedPath); // containing folder
string y = Path.GetDirectoryName(x); // 1 folder up


y may be null, if x is a root folder (e.g. x = C:\)


这篇关于如何从文件位置遍历一个文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆