splitting filename

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

Vendor Name.pdf

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.

I’d use regular expressions for this, personally:

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?

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?

That’s going to get ugly fast :slight_smile: 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. :slight_smile:

Thank you again, works great! My code on the other hand leaves a lot to be desired I imagine :wink: But your regex is working flawlessly. Thanks again!

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?

Oops, there’s supposed to be a $ sign at the very end of the pattern.

Thanks!