Tuesday, 20 August 2013

NODE.JS - how to handle a mix of OS and URL-style "paths" correctly?

NODE.JS - how to handle a mix of OS and URL-style "paths" correctly?

In my node.js app I have functions which can be passed either
OS-style paths e.g. c:\my\docs\mydoc.doc (or /usr/docs/mydoc.doc or
whatever is local)
File URLS e.g. file://c:/my/docs/mydoc.doc (which I'm not sure about the
validity of '\'s in??)
Either way, I need to check to see if they refer to a specific location
which will always exist as a local OS-style path e.g. c:\mydata\directory\
or /usr/mydata/directory
Obviously for OS-style paths I can just compare them as strings - they
SHOULD always be the same (they're created with path) but FILE:// URLS
don't necessarily use path.sep and so won't "string match"?
Any suggestions as to the best way to handle this (I'm personally tempted
to break EVERYTHING by one-or-more slashes of either sort and then check
each piece??

No comments:

Post a Comment