how to resolve Windows pathnames into cygwin ones

Gerhard Häring gh at
Fri Jan 18 17:42:21 CET 2008

mgierdal at 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.

You can call the cygpath utility:

 >>> import commands
 >>> commands.getoutput("cygpath c:/windows")

-- Gerhard

More information about the Python-list mailing list