繁体   English   中英

有什么更好的方法来删除C#2.0中文件路径中附加的子文件夹

[英]What's a better way to remove a sub folder that attached in the file path in C# 2.0

   string EV_HOME = System.Environment.GetEnvironmentVariable("EV_HOME");
   string myFilePath = EV_HOME + "\\MyFolder\\MySubFolder";

假设EV_HOME返回C:\\ myprogram \\ leanrning \\ anotherfolder

我怎样才能删除anotherfolder文件夹并获取myFilePath这样

C:\\ myprogram \\ leanrning \\ MyFolder \\ MySubFolder

我所知道的是循环Ev_HOME值,并将每个(除了最后一个除外)构建为新字符串。

谢谢。

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication12
{
    class Program
    {
        static void Main(string[] args)
        {
            string EV_HOME = @"C:\myprogram\leanrning\anotherfolder\";
            string parentFolder = new System.IO.DirectoryInfo(EV_HOME).Parent.FullName;
            string myFilePath = parentFolder + "\\MyFolder\\MySubFolder";
            Console.WriteLine(myFilePath);
        }
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM