Click here to Skip to main content
11,483,586 members (64,281 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 2: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 Sergey Alexandrovich Kryukov 305
1 Frankie-C 195
2 Raje_ 155
3 OriginalGriff 142
4 Abhipal Singh 108
0 Sergey Alexandrovich Kryukov 8,444
1 OriginalGriff 7,903
2 Sascha Lefèvre 3,114
3 Maciej Los 2,521
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web03 | 2.8.150520.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