how to resolve Windows pathnames into cygwin ones

apatheticagnostic apatheticagnostic at gmail.com
Fri Jan 18 12:12:57 EST 2008


On Jan 18, 11:48 am, Grant Edwards <gra... at visi.com> wrote:
> On 2008-01-18, apatheticagnostic <apatheticagnos... at gmail.com> wrote:
>
>
>
> > On Jan 18, 11:10 am, "mgier... at gmail.com" <mgier... at gmail.com> wrote:
> >> I am looking for a function to resolve 'F:/foo/bar' into '/cygdrive/f/
> >> foo/bar'. I get the original dirpath from tkFileDialog.askdirectory in
> >> a Windows form and none of os.path.* functions seem to resolve it to a
> >> cygwin form. Rather they _append_ it to the current directory,
> >> resulting at best in a monster '/cygdrive/c/whatever/f/foo/bar'.
> >> It's all being developed under cygwin currently (so it is a kind of
> >> mixed environment), but I would like the fix to work correctly in any
> >> environment.
>
> >> Thanks,
> >> Marcin
>
> > Well, you could write it yourself....
>
> > (assuming path is a string, here's a first go at it...)
> > def path_into_cygpath(path):
> >     drive, destination = path.split(':')
> >     newpath = '/cygdrive/' + drive.lower() + destination
> >     return newpath
>
> Don't forget to convert backslashes into forward slashes.
>
> --
> Grant Edwards                   grante             Yow! TONY RANDALL!  Is YOUR
>                                   at               life a PATIO of FUN??
>                                visi.com

Whoops.

Here we go then (are forward slashes valid in a filename in windows?)
def path_into_cygpath(path):
    drive, destination = path.replace('\\','/').split(':')
    return '/cygdrive/' + drive.lower() + destination



More information about the Python-list mailing list