how to resolve Windows pathnames into cygwin ones

Reedick, Andrew jr9445 at ATT.COM
Fri Jan 18 12:25:56 EST 2008


> -----Original Message-----
> From: python-list-bounces+jr9445=att.com at python.org [mailto:python-
> list-bounces+jr9445=att.com at python.org] On Behalf Of
mgierdal at gmail.com
> Sent: Friday, January 18, 2008 11:11 AM
> To: python-list at python.org
> Subject: how to resolve Windows pathnames into cygwin ones
> 
> 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.
> 

Firstly, '/cygdrive' is overrated.  Cygwin will accept:  'ls c:\\foo'
and 'ls c:/foo'


s= 'f:\\foo\\bar'

print re.sub(r'\\', '/', s)

m = re.match('^(.):(.*)$', s)
print '/cygdrive/' + m.group(1) + re.sub(r'\\', '/', m.group(2))

*****

The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. GA621





More information about the Python-list mailing list