Click here to Skip to main content
15,916,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i have run time path,,, like
@"D:\ToZipFolder";
@"D:\abc\ToZipFolder";
@"D:\xyz\abc";
@"D:\xyz\abc\a\folder";

so i need


@"D:
@"D:\abc
@"D:\xyz
@"D:\xyz\abc\a

How can i do that,,?
Posted
Updated 12-May-21 20:18pm
Comments
ZurdoDev 5-Sep-12 8:06am    
What language? C#? Use the improve question link to add some information.
Ali_100 5-Sep-12 8:17am    
Yes C#
[no name] 5-Sep-12 8:21am    
string helloOriginal = "Hello! World!";
string newString = helloOriginal.Substring(0,helloOriginal.LastIndexOf('!'));

//Delete Last Directory from path
new System.IO.DirectoryInfo(Path).Delete(true);
 
Share this answer
 
Comments
CHill60 13-May-21 3:44am    
OP wanted to remove the last folder from a path variable NOT delete the actual directory
C#
string path = @"D:\abc\ToZipFolder";
string newpath = System.IO.Path.GetDirectoryName(path);

newpath is :
D:\abc
 
Share this answer
 
v2
Try:
C#
string src = @"D:\xyz\abc\a\folder";
string dest = src.Substring(0, src.LastIndexOf('\\'));
 
Share this answer
 
Comments
Kuthuparakkal 5-Sep-12 8:26am    
will not work always:
if src is @"D:\xyz\abc\a\folder\" will return @"D:\xyz\abc\a\folder"
and if src is @"D:\xyz\abc\a\folder" will return @"D:\xyz\abc\a"

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