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 8485557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:40:54+00:00 2026-06-10T20:40:54+00:00

I have a filepath that follows the following pattern: Some\File\Path\Base\yyyy\MM\dd\HH\mm\Random8.3 I want to extract

  • 0

I have a filepath that follows the following pattern:

Some\File\Path\Base\yyyy\MM\dd\HH\mm\Random8.3

I want to extract everything from 2012 and beyond, but the problem is that while the right side is standard the base directory can be different for each record.

Here are two examples:

  1. C:\Temp\X\2012\08\27\18\35\wy32dm1q.qyt
    Returns: 2012\08\27\18\35\wy32dm1q.qyt

  2. D:\Temp\X\Y\2012\08\27\18\36\tx84uwvr.puq
    Returns: 2012\08\27\18\36\tx84uwvr.puq

Right now I’m grabbing the LastIndexOf(Path.DirectorySeparatorChar) N number of times to get the index of the string right before 2012, then getting the substring from that index on. But, I have a feeling that maybe there is a better way?

  • 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-10T20:40:55+00:00Added an answer on June 10, 2026 at 8:40 pm

    Here’s a solution that uses regular expressions, assuming the format you’re looking for always contains \yyyy\MM\dd\HH\mm.

    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(ExtractPath(@"C:\Temp\X\2012\08\27\18\35\wy32dm1q.qyt"));
            Console.WriteLine(ExtractPath(@"D:\Temp\X\Y\2012\08\27\18\36\tx84uwvr.puq"));
        }
    
        static string ExtractPath(string fullPath)
        {
            string regexconvention = String.Format(@"\d{{4}}\u{0:X4}(\d{{2}}\u{0:X4}){{4}}\w{{8}}.\w{{3}}", Convert.ToInt32(Path.DirectorySeparatorChar, CultureInfo.InvariantCulture));
    
            return Regex.Match(fullPath, regexconvention).Value;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have for example .pdf file (path to that file). How to open this
I have a batch file that requires the user to enter a file path.
I have a function that lets me write the file-path of files to a
I have a program that walks the file system hierarchy listing the file path
I have a controller action that has the same name as a file path.
I have a method in my windows service as follows: System.IO.File.Copy(path, ConfigurationManager.AppSettings[BulkInsertGiftRegisterCreatorDirectory] + System.IO.Path.GetFileName(path));
I have a function ClassA::FuncA(const char *filePath) and want to copy this const char
I have a file path, and I need to get the data of the
So as it stands I have a form that hands a file to my
I have a function that looks as follows: let isInSet setElems normalize p =

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.