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:
C:\Temp\X\2012\08\27\18\35\wy32dm1q.qyt
Returns:2012\08\27\18\35\wy32dm1q.qyt
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?
Here's a solution that uses regular expressions, assuming the format you're looking for always contains \yyyy\MM\dd\HH\mm.
A c# solution would be
I don't think there's anything wrong w/ your current approach. It's likely the best for the job.
I'd keep it simple (KISS). Easier to debug/maintain and probably twice as fast as regex variant.