how to resolve Windows pathnames into cygwin ones

M

mgierdal

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
 
G

Gerhard Häring

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:
'/c/windows'

-- Gerhard
 
A

apatheticagnostic

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
 
G

Grant Edwards

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.
 
A

apatheticagnostic

Don't forget to convert backslashes into forward slashes.

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
 
R

Reedick, Andrew

-----Original Message-----
From: [email protected] [mailto:python-
[email protected]] On Behalf Of (e-mail address removed)
Sent: Friday, January 18, 2008 11:11 AM
To: (e-mail address removed)
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
 
M

mgierdal

Well yes, I was hoping for a library function, but none provides it.
Thanks for the code. Works nicely.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top