[英]Is there a way of dynamically locating a change of path of a sub-folder/sub-file of my current c# Winforms application?
[英]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.