Click here to Skip to main content
11,712,126 members (71,812 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: delete filepath path
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 5-Sep-12 1:59am
Ali_1001.4K
Comments
ryanb31 at 5-Sep-12 8:06am
   
What language? C#? Use the improve question link to add some information.
Ali_100 at 5-Sep-12 8:17am
   
Yes C#
Karthik_J, Coimbatore at 5-Sep-12 8:21am
   
string helloOriginal = "Hello! World!";
string newString = helloOriginal.Substring(0,helloOriginal.LastIndexOf('!'));
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try:
string src = @"D:\xyz\abc\a\folder";
string dest = src.Substring(0, src.LastIndexOf('\\'));
  Permalink  
Comments
Kuthuparakkal at 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"
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

string path = @"D:\abc\ToZipFolder";
string newpath = System.IO.Path.GetDirectoryName(path);
newpath is :
D:\abc
  Permalink  
v2

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

  Print Answers RSS
0 CHill60 335
1 Sergey Alexandrovich Kryukov 244
2 OriginalGriff 230
3 Andy Lanng 160
4 Maciej Los 130
0 CHill60 335
1 Sergey Alexandrovich Kryukov 245
2 OriginalGriff 230
3 Andy Lanng 160
4 Maciej Los 130


Advertise | Privacy | Mobile
Web02 | 2.8.150819.1 | Last Updated 5 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100