我工作的東西,需要通過文件系統和任何給定的路徑遍歷,我需要知道我是如何「深」是在文件夾結構。這是我目前使用的:C#獲取給定路徑的文件夾深度的最佳方法?
int folderDepth = 0;
string tmpPath = startPath;
while (Directory.GetParent(tmpPath) != null) {
folderDepth++;
tmpPath = Directory.GetParent(tmpPath).FullName;
}
return folderDepth;
這個工程,但我懷疑有更好/更快的方式?非常感謝任何反饋。
就像這個想法很多!只是一個簡短的說明,長度是一種財產而不是一種方法。 – BFree 2008-11-25 00:46:09