Convert between Windows style paths and POSIX style paths

Peter Hansen peter at engcorp.com
Thu Jul 10 18:15:01 EDT 2003


Noah wrote:
> 
> Does anyone have a function to convert back and forth between
> NT style paths and POSIX style? It seems trivial, but
> I want to make sure I don't overlook some obscure detail.
> Is it a simple matter of translating / and \ characters?
> 
> FYI, I need a Python function that does what cygpath does so that
> I can run a script on either NT or UNIX or Cygwin.
> I want my config files use one style of path.

You can use forward slashes in paths under Win32, except at the
command prompt.

Even if you switch to use all forward slashes, however, what do
you plan to do about drive letters?  There is no obvious mapping
to anything under POSIX, I think.  Are you planning on disallowing
paths that go anywhere but the current drive under NT?

-Peter




More information about the Python-list mailing list