Reputation: 1971
string EV_HOME = System.Environment.GetEnvironmentVariable("EV_HOME");
string myFilePath = EV_HOME + "\\MyFolder\\MySubFolder";
Suppose EV_HOME
return C:\myprogram\leanrning\anotherfolder
How can I remove the folder anotherfolder
and get myFilePath
as this
C:\myprogram\leanrning\MyFolder\MySubFolder
What I know is loop the Ev_HOME value and build each one (except the last one) as a new string.
thanks.
Upvotes: 0
Views: 47
Reputation: 2342
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);
}
}
}
Upvotes: 1