delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/01/15/03:28:47

From: ggp AT informix DOT com (Guy G. Piggford)
Subject: Re: Path name conversions, Posix <-> Win32
15 Jan 1998 03:28:47 -0800 :
Message-ID: <3.0.3.32.19980113122711.0092d630.cygnus.gnu-win32@pop.pdx.informix.com>
References: <000601bd1fa0$2436c700$b638cb83 AT gust DOT niwa DOT cri DOT nz>
Mime-Version: 1.0
To: "Mark Hadfield" <m DOT hadfield AT niwa DOT cri DOT nz>,
"Gnu-Win32 Mailing List" <gnu-win32 AT cygnus DOT com>

At 10:22 AM 1/13/98 +1300, Mark Hadfield wrote:
>Where can I find command-line utilities for conversion between Cygwin32
>Posix-style and Win32 path names? Eg, a pair of utilities that work like
>this:
>
>bash$ echo //C/foo | win32path
>C:\foo
>bash$ echo C:\\foo | posixpath
>//C/foo
>
>I know it's not too difficult to implement this via string substitution in
>awk or bash. (The above examples are real output, produced by a pair of
>Python scripts that I wrote.) What I really want is something that knows
>about Cygwin32 mounts, eg:

Well you can try something like this:

function win32path
{
    declare file=$1
    file=$( echo $file | sed -e 's,//\(.\),\1:,' \
		`mount | sed -n 's,\([^ ]*\) *\(/[^ ]*\).*,-e s~^\2~\1~,p'` \
		-e 's,/,\\,g' \
		-e 's,:\([^\\]\),:\\\1,g')
    echo $file
}

It doesn't like getting spaces in path names since it only acts upon $1,
but other than that it doesn't do too badly.  I'd be interested in any
improvements though, I'm sure that it's probably simpler to do in perl, but
I don't know it well enough.

I've never found a need for the posixpath version so I don't have a canned
one handy.

Guy

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019