Click here to Skip to main content
12,078,742 members (47,055 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: 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 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#
Karthik_J, Coimbatore 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 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
Top Experts
Last 24hrsThis month


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