Click here to Skip to main content
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.3K
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)



Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 5 Sep 2012
Copyright © CodeProject, 1999-2014
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