[英]Remove one directory from full directory path
I have a directory path of C:\\Subdir1\\Subdir2\\Subdir3\\filename.xml
. 我的目录路径为
C:\\Subdir1\\Subdir2\\Subdir3\\filename.xml
。
I need to first check if the file, filename.xml
exists in the root of "Subdir2"
(one level back) before looking in "Subdir3"
. 在查看
"Subdir3"
之前,我需要首先检查文件filename.xml
存在于"Subdir2"
的根目录中(一级返回)。 How can I easly parse this with Path.GetPathRoot(filename)
? 如何使用
Path.GetPathRoot(filename)
解析它?
IE IE
First see if this is true: 首先看看是否属实:
C:\\Subdir1\\Subdir2\\filename.xml
C:\\ Subdir1 \\ Subdir2 \\ filename.xml中
If not true, then default to C:\\Subdir1\\SubDir2\\Subdir3\\filename.xml
for the file. 如果不为true,则默认为文件的
C:\\Subdir1\\SubDir2\\Subdir3\\filename.xml
。
Directory.GetParent(dir).FullName
试试这个Directory.GetParent
和System.IO.File.Exists
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.