Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9284127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:48:41+00:00 2026-06-18T18:48:41+00:00

In .NET (VB or C#) Does anyone know a simple way to remove the

  • 0

In .NET (VB or C#) Does anyone know a simple way to remove the ‘head’ directory from a file path String, meaning if I have path that looks something like this: Directory1/Directory2/Directory3I want to get Directory2/Directory3 back. I know there are some ways to do it, like split it into an array, and then starting with the second element concatenate it all back, I just feel like that, that’s its an extremely inefficient way of doing it and was wondering if there is a better way to do this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T18:48:42+00:00Added an answer on June 18, 2026 at 6:48 pm

    It depends on what you’re looking for. If you know that things are in the form dir1/dir2/dir3/dir4..., then you can just look for the first / and take everything after that:

    string dir = "dir1/dir2/dir3";
    var pos = dir.IndexOf('/');
    if (pos != -1)
    {
        result = dir.Substring(pos+1);
    }
    

    If you can also accept full path names of the form c:\dir\dir\file.ext or \\server\dir\dir\file.ext, then you’ll probably want to make sure that you make any relative paths into full paths first. Then use the methods in the System.IO.Path class to extract the drive or server names before using something like the IndexOf trick above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does the .NET Compact Framework have a service pack? If so does anyone know
Does anyone know how to construct a format string in .NET so that the
Does anyone know of a way to create Code Coverage reports for C#/.NET projects
Does anyone know of a way to start ASP.NET MVC 4 project without including
Does anyone know how to add a simple search textbox on an ASP.NET Dynamic
Except https://www.php.net/manual/en/book.ktaglib.php and http://getid3.sourceforge.net/ does anyone know of any other way to work from
Does anyone know of an ASP.NET guide to implementing OpenID and what information can
Does anyone know how to move my SDL.net video surface around the screen programtically?
Does anyone know how to pass a C# ASP.NET array to a JavaScript array?
Does anyone know of a CSS Adapter for the LinkButton control for ASP.Net 2?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.