Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a string like below

string path = @"C:\Program Files\TEST\Project Name\Tester.exe";


I need string path value up to "C:\Program Files\TEST\Project Name\" only
this is my code
string strt = path.Remove(path.Length-10);


but I don't want to use length how to do it
please help me.


Thanks,
RG
Posted
Comments
Kenneth Haugland 24-Mar-14 7:36am    
Convert it to a path instead i.a. IO.Path and get the parant directory
Ramug10 24-Mar-14 7:39am    
how to do it??
ArunRajendra 24-Mar-14 7:36am    
Do you want a path of the file?
Ramug10 24-Mar-14 7:39am    
s

1 solution

Try this

C#
string path = @"C:\Program Files\TEST\Project Name\Tester.exe";
FileInfo fi1 = new FileInfo(path);

if (!fi1 .Exists)
{
    return;
}

//This line will return the file path
string dirPath = fi1.DirectoryName;
 
Share this answer
 
Comments
Ramug10 24-Mar-14 7:56am    
yaa it's working.

Thank you very much
ArunRajendra 24-Mar-14 7:58am    
Please rate the solution with 5 being highest.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900