- May 13, 2016 at 5:52 am #39036
Hello, I'm writing a larger script, but one of the pieces I need is to split the file name into 2 parts:
This File would need split into 2 parts, the first part being the saved to like:
$date = "06-12-07"
$vendor = "Vendor Name"
06-12-07 Vendor Name.pdf
And to complicate things, sometimes the file name would be just like
Without the year information, which is ok. I'm not sure exactly how to split it up, I cant use split as the filename can have multiple spaces in it.
Any help would be greatly appreciated.May 13, 2016 at 6:05 am #39039
I'd use regular expressions for this, personally:May 13, 2016 at 6:13 am #39040
Thank you Dave, that works perfectly! I wish I knew regex a lot better (than 0). Do you have any helpful links or books you use?May 13, 2016 at 6:15 am #39041
Ah...sorry one more thing...I noticed a date using underscores...
12_14_12_ – Vendor name.pdf
How could I edit your regex to include these and maybe any other chars users can find and plug in?May 13, 2016 at 6:20 am #39043
That's going to get ugly fast 🙂 I've updated the gist's pattern, give it a try.
I learned Regex years ago from this site: http://www.regular-expressions.info/ . What I like about it is that it's got the general "applies to everything" information, but it's also got sections specific to many different implementations. So you can get data about perl, java, .NET, PowerShell, VBScript, whatever. 🙂May 13, 2016 at 6:29 am #39046
Thank you again, works great! My code on the other hand leaves a lot to be desired I imagine 😉 But your regex is working flawlessly. Thanks again!May 13, 2016 at 6:51 am #39048
Crap...last Time I will bug you about this...
The name can also be like
10_10_10 F. last.pdf
All files will end in pdf, any way to allow for .'s in the vendor name and just exclude the extension?May 13, 2016 at 6:54 am #39049
Oops, there's supposed to be a $ sign at the very end of the pattern.May 13, 2016 at 6:54 am #39050
You must be logged in to reply to this topic.